I need to rename any file with the name already exists in the folder. After it is renamed that I can move it.
if [ -e $BACKUP$PARAM1 ]; then
echo -e "In this directory there is already a file with the same name. \n"
read -p "Please, write a new filename: " newname
mv "$PARAM1" "$newname"
mv $PARAM1 $BACKUP
fi
The first mv command doesn't work. Any idea to solve it?
I write a dirty simulation:
in $BACKUP$PARAM1
there is the full folder of a file moved to Backup directory. $BACKUP
contains "Backup/", $PARAM1
contains "song.mp3", so $BACKUP$PARAM1
= Backup/song.mp3.
If in Backup folder already exists a file called "song.mp3", I'll rename my file before to move in Backup.
So I write a new filename: "music.mp3", stored in $newname
then proceed to the change of name using the mv command: mv "$PARAM1" "$newname"
---> "song.mp3" to "music.mp3".
At the and, I move the renamed file to the "Backup" folder: mv $PARAM1 $BACKUP
to obtain: "Backup/music.mp3".