View Full Version : Usage of mv in bash shell script
Yabadoo
30th September 2006, 15:28
Hello all,
I want to use the mv command in a script named rename.sh, but when i run the command on the prompt (sh rename.sh) i have the error "mv: command not found". :confused: The script is in mode 0777.
Below you will find the code i want to use.
Any help is welcome !
#!/bin/bash
PATH="/var/opt/"
#Rename before
cd $PATH
mv "file1.php" "file1.php.org"
mv "file1.php.1" "file1.php"
exit 0
fi
sjau
30th September 2006, 15:56
Try this:
#!/bin/bash
PATH="/var/opt/";
MV=/bin/mv;
#Rename before
cd $PATH
MV "file1.php" "file1.php.org"
MV "file1.php.1" "file1.php"
exit 0
fi
Yabadoo
30th September 2006, 16:21
Try this:
#!/bin/bash
PATH="/var/opt/";
MV=/bin/mv;
#Rename before
cd $PATH
MV "file1.php" "file1.php.org"
MV "file1.php.1" "file1.php"
exit 0
fi
I still have the same error "MV: command not found" ???
sjau
30th September 2006, 16:59
then have a look where the binary for "mv" acutally is and adjust the path.
Yabadoo
30th September 2006, 17:07
I did a "locate mv", and the path where it is /bin/mv,
exactly in the way it stands in the script....
falko
1st October 2006, 13:32
Try this:
#!/bin/bash
PATH="/var/opt/";
MV=/bin/mv;
#Rename before
cd $PATH
MV "file1.php" "file1.php.org"
MV "file1.php.1" "file1.php"
exit 0
fi
Either use
#!/bin/bash
PATH="/var/opt/";
MV=/bin/mv;
#Rename before
cd $PATH
$MV "file1.php" "file1.php.org"
$MV "file1.php.1" "file1.php"
exit 0
fi
or adjust the PATH variable in your original script:
#!/bin/bash
PATH="/bin:/var/opt/"
#Rename before
cd /var/opt
mv "file1.php" "file1.php.org"
mv "file1.php.1" "file1.php"
exit 0
fi
sjau
1st October 2006, 14:25
Stupid me, forgot to "$" ^^
Yabadoo
1st October 2006, 16:51
Stupid me, forgot to "$" ^^
Thanks for the help Falko and Sjau !!!!.
The $ did the trick, is runs perfect now.... :)
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.