LInux 恢复脚本返回意外标记

标签 linux shell restore

我正在为 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/

相关文章:

linux - 在 Linux 中创建一个虚拟文件

python - 找出每个 clientId 的新旧映射之间的差异

bash - 在Solaris的Bash Shell下输入 "env"、 "export"、 "set"命令后输出的命令有什么区别?

sql - 如何从备份文件中检索数据库的逻辑文件名

tensorflow - 在 tensorflow 中恢复使用可变输入长度训练的模型导致 InvalidArgumentError

php - strpos 未返回正确的结果

linux - 在一个脚本中分组不同的 linux 命令

elasticsearch - ElasticSearch-将索引还原到较低版本

linux - 在虚拟专用服务器上设置网站

LINUX CP : I need to copy all files from one directory to another without copying any sub-directories