•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 391,914 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,720 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 10580 | Replies: 2
![]() |
•
•
Join Date: Feb 2005
Posts: 1
Reputation:
Rep Power: 0
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.
•
•
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,879
Reputation:
Rep Power: 32
Solved Threads: 107
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.
Dani the Computer Science Gal
Do you run a computer-related website? Feature it in our niche link directory!
Do you run a computer-related website? Feature it in our niche link directory!
•
•
Join Date: Apr 2005
Posts: 3
Reputation:
Rep Power: 0
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
apple bbc cd cellphone choose computer core debian dell desktop development enterprise fedora games garnet gentoo gpl hardware ibm infrastructure install kernel laptop linux microsoft mobile news novell open open source openbsd openoffice operating os palm palmos red hat scripting security server source sun suse system ubuntu unix vista web web development windows
- new to linux shell script??????? (Shell Scripting)
- Sending email from a shell script (Shell Scripting)
- For Pay Shell Script - Zip / FTP / Delete transactional files (Shell Scripting)
- Making a shell script executable from any directory (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:-} "?



Linear Mode