我正在为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发布于 2014-11-27 13:31:17
while循环的语法错误。在bash中,while循环应该如下所示:
while read -f filename ; do
# here goes the loops body code
done注意我是如何在循环头中添加“;do”的,以及我是如何用“do”而不是"fi“来结束循环的。
https://stackoverflow.com/questions/27163491
复制相似问题