问题描述
我通过虚拟机使用Linux,
I'm using Linux through a virtual machine,
我的课程我要创建3个脚本,脚本,它们之一是要删除的文件恢复到或者用户提出或原来的位置的位置
for my coursework i have to create 3 scripts, one of they scripts is to restore deleted files to either a location the user puts in or to the original location
这是我有我的剧本至今
#!/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
但是当我尝试恢复该文件我得到一个错误说
but when i try restore the file i get an error saying
grep: cd: no such file or directory
mv: cannot move `test' to `': no such file or directory
在sricpt现在的作品,当我做恢复-n
但它仍然不工作,当我做resotre
the sricpt now works when i do restore -n but it still doesnt work when i do resotre
我的脚本更新它现在看起来像:
update of my script it now looks like :
#!/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
now I'm getting the error:mv: missing destination file operand after `' when i try to do restore test.txt
推荐答案
下面是清理语法:
#!/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 -i $文件名$ LOCATION1$位置
:既不位置
或 LOCATION1
在使用前,这里定义的。
But unfortunately I am unable to infer what your goal is in the else
clause; for instance: mv -i $filename "$location1" $location
: neither location
or location1
is defined before use here.
这篇关于在Linux中恢复脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!