linux - MV 命令给我的是相同的文件错误

标签 linux shell

所以我正在构建这个脚本以从“垃圾”目录中获取一个文件并将其移动到主目录。我收到错误 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/

相关文章:

性能差和高 CPU 负载调优的 Mysql - cs-cart linux

linux - 导出在另一个文件中定义的变量

linux - 如何使用 egrep 只返回一行的一部分

python - Cron 作业无法一直正常工作。 Python 只完成了我的脚本的一半工作

linux - Tomcat自动恢复

c - Linux 和 Windows 之间 fwrite 的不同行为

node.js - 使 nginx 和 node.js 有一个共同的根文件夹

shell - 将 grep 结果分配给 shell 变量后丢失换行符

linux - Bash 脚本和别名

linux - python : How to repeat every 24 hours