简体   繁体   中英

MV command giving me are the same file error

So I am building this script to take a file from the "trash" directory and move it to the home directory. I am getting an error mv:/home/user/Trash/ and /home/user/Trash are the same file. The problem is I am moving the file to /home/user. I can't figure out why it is giving me this error.

Script:

trash="/home/user/Trash"
homedirectory="/home/user/"
for files in "$trash"/*
do
echo "$(basename $files) deleted on $(date -r $files)"
done
echo "Enter the filename to undelete from the above list:"
read $undeletefile
mv $trash/$undeletefile $homedirectory

Output:

myfile2 deleted on Thu Jan 23 18:47:50 CST 2014
trashfile deleted on Fri Feb 28 23:07:33 CST 2014
Enter the filename to undelete from the above list:
trashfile
mv: `/home/user/Trash/' and `/home/user/Trash' are the same file

I think your problem is in the read command. You are not supposed to add $ to it. Try:

read undeletefile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM