我通过虚拟机使用 Linux,
对于我的课程,我必须创建 3 个脚本,其中一个脚本是将已删除的文件恢复到用户放入的位置或原始位置
到目前为止,这是我的脚本所拥有的
#!/bin/sh
if [ "$1" == "-n" ]
then
cd /root/michael/trash
restore`grep "$2" cd /root/michael/store`
filename=`basename "$restore"`
echo "Where would you like to save the file?"
read location
location1=`readlink -f "$location"`
mv -i $filename "location1"/filename
else
cd /root/michael/trash
restore=`grep "$2" cd /root/michael/store`
filename=`basename "$restore"`
mv -i $filename "location1" $location
fi
但是当我尝试恢复文件时,我收到一条错误消息
grep: cd: no such file or directory
mv: cannot move `test' to `': no such file or directory
现在,当我恢复 -n 时,sricpt 可以工作,但当我重新执行时它仍然无法工作
我的脚本的更新现在看起来像:
#!/bin/sh
if [ "$1" == "-n" ]
then
cd /root/michael/trash
restore`grep "$2" /root/michael/store`
filename=`basename "$restore"`
echo "Where would you like to save the file?"
read location
location1=`readlink -f "$location"`
mv -i $filename "location1"/filename
else
cd /root/michael/trash
restore=`grep "$2" /root/michael/store`
filename=`basename "$restore"`
mv -i $filename "location1" $location
fi
现在我收到错误消息:mv:当我尝试恢复 test.txt 时,`' 后缺少目标文件操作数