所以我构建这个脚本是为了从“垃圾”目录中获取一个文件并将其移动到主目录。我收到一个错误mv:/home/user/Trash/和/home/user/Trash是同一个文件。问题是我正在将文件移动到/home/user。我不明白为什么它会给我这个错误。
脚本:

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

输出:
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

最佳答案

我认为您的问题出在read命令中。你不应该给它加上$
尝试:

read undeletefile

关于linux - MV命令给我的是同一个文件错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22212427/

10-14 16:55