我的课程涉及编写一个 linux 脚本以从伪垃圾文件夹中“恢复”文件。我已经这样做了,它看起来应该可以工作,但事实并非如此。相反,我收到一条错误消息:
sed:-e 表达式#1,字符 2:命令后的额外字符
但我不明白为什么,因为我没有在代码中的任何地方使用 -e 表达式。然而,我的大脑因为盯着代码看太久了,以至于它可能只是一个我看不到的愚蠢错误。任何帮助将不胜感激!
这是我的代码:
#!/bin/sh
if [ "$1" = "-n" ]
then
##if command is used with -n, prompts user to enter a new location for the file
cd ~/my-documents/mydir01/trashbin
restore=`sed "$2" ~/my-documents/mydir01/locations`
name=`basename "$restore"`
echo $name
echo "Enter new location for this file."
read loc
echo $loc
mv -i `"$name" "$newloc"/"$name"`
else
##file will be restored to its previous location
cd ~/my-documents/mydir01/trashbin
restore=`sed "$1" ~/my-documents/mydir01/locations`
loc=`dirname "$restore"`
echo $loc
name=`dirname "$restore"`
mv $1 $name
fi