在 Linux 中恢复脚本



我正在通过虚拟机使用 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 现在可以工作但是当我做 reotre 时它仍然不起作用

更新我的脚本现在看起来像:

#!/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:当我尝试恢复测试时,"之后缺少目标文件操作数.txt<</p>

div class="ans>

以下是清理后的语法:

#!/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

但不幸的是,我无法推断您在else子句中的目标是什么;例如:mv -i $filename "$location1" $location:在这里使用之前,既没有定义location也没有定义location1

grep 需要两个参数,一个模式和一个文件。你已经给了它三个,一个模式,命令cd,和一个文件。 这里不需要cd

相关内容

  • 没有找到相关文章

最新更新