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.

Recommended Answers

All 2 Replies

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.

Hey buddy, what youre trying to do can easily be implement with a TEST condition at the start of your shell script. For example:


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
#perform operations on file
echo -e "File Doesnt Exist!!!"

This should help you out, giving you the basic idea that you can now employ with the new file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.