| | |
Linux Shell Script
![]() |
•
•
Join Date: Feb 2005
Posts: 1
Reputation:
Solved Threads: 0
I have been given the task of writing a small shell script which does the following:
It takes two arguments: the first argument is the name of the original file and the second argument is the new name for the file. If a user does not provide two arguments, a usage message will appear on the screen and the script will exit. The script should check to see if the new name already exists. If the name does already exist the script should prompt the user for a decision about whether the file should be overwritten.
I know it is quite lengthy but any help will be appreciated.
It takes two arguments: the first argument is the name of the original file and the second argument is the new name for the file. If a user does not provide two arguments, a usage message will appear on the screen and the script will exit. The script should check to see if the new name already exists. If the name does already exist the script should prompt the user for a decision about whether the file should be overwritten.
I know it is quite lengthy but any help will be appreciated.
Where exactly are you having the problem? Have you attempted to write the code yourself? We will help you debug, diagnose, or give you ideas, but we have a policy where we won't write your code for you.
•
•
Join Date: Apr 2005
Posts: 3
Reputation:
Solved Threads: 0
Hey buddy, what youre trying to do can easily be implement with a TEST condition at the start of your shell script. For example:
#!/bin/bash
echo -e "Reading input file name $1 from user..."
echo -e "Reading new file name $2 from user.."
if [ -r $1 ] #checks if files exists and is readable
then
#perform operations on file
else
echo -e "File Doesnt Exist!!!"
fi
This should help you out, giving you the basic idea that you can now employ with the new file.
#!/bin/bash
echo -e "Reading input file name $1 from user..."
echo -e "Reading new file name $2 from user.."
if [ -r $1 ] #checks if files exists and is readable
then
#perform operations on file
else
echo -e "File Doesnt Exist!!!"
fi
This should help you out, giving you the basic idea that you can now employ with the new file.
![]() |
Similar Threads
- Sending email from a shell script (Shell Scripting)
- Using Shell Script how to send mail automatically (Shell Scripting)
- new to linux shell script??????? (Shell Scripting)
- Shell Script for yesterday's date. (Shell Scripting)
- Shell Script Issue (Shell Scripting)
- Linux Shell Script needs help writing program (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: Shell Scripting problem and related awk issues
- Next Thread: what's the meaning of " ${1:-} "?
| Thread Tools | Search this Thread |







