February 17th, 2003, 08:42 PM
HELP NEEDED in writing a script to rename a file.......
I need some help in writing a shell script in a Bourne shell to do the following task,
prompts a user for the source and target files. If the absolute path is not given, then assume that the file is in the home directory. Should also check if have permissions to rename the file. If cannot execute the command for any reason, print the reason on the screen. If it is possible, rename the file.
I have been struggling to come up with a solution but can't get it working. Any help is really appreciated.
February 20th, 2003, 09:21 AM
The following should do what you want:
However, assuming this is not a homework assignment, why do you want to do this? Why not just use "mv" with explicit pathnames? Generally, programs that take command-line arguments are much preferred in the Unix world to those that are interactive.
case "$1" in
echo -n 'Source: '
if [ ! -e "$src" ]; then
echo $src does not exist >&2
echo -n 'Destination: '
mv $src $dst