我正在为 Linux 创建一个具有恢复功能的回收站。到目前为止,我有一个脚本可以成功地将文件移动到回收站,但是我的还原脚本无法正常工作。
恢复脚本的目的是提示用户选择一个目录,然后将选定的文件从回收站移动到该目录。但是,当我运行脚本时,遇到“意外标记;fi”错误或我尝试用其结束文件的任何标记。谁能看到我脚本中的错误?
#!/bin/bash
#Changes directory to location of recycle bin
while read -r filename
echo "Where would you like the file to be restored to?"
read newlocation
mv -i ~/recycle/$filename $newlocation
echo "File has been restored!"
fi
最佳答案
您的 while 循环语法错误。在 bash 中,while 循环应该如下所示:
while read -f filename ; do
# here goes the loops body code
done
请注意我是如何在循环头中添加“;do”以及如何使用“done”而不是“fi”来结束循环的。
关于LInux 恢复脚本返回意外标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27163491/