因此,我正在构建此脚本以从“trash”目录中获取文件并将其移动到主目录。我收到错误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
答案 0 :(得分:1)
我认为您的问题出在read
命令中。您不应该向其添加$
。
尝试:
read undeletefile