简体   繁体   English

MV命令给我的是同一个文件错误

[英]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. 我收到错误MV:/ home / user / Trash /和/ home / user / Trash是同一文件。 The problem is I am moving the file to /home/user. 问题是我将文件移到/ 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. 我认为您的问题出在read命令中。 You are not supposed to add $ to it. 您不应在其中添加$ Try: 尝试:

read undeletefile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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