![UNIX 语法(和其他错误)](https://linux22.com/image/153936/UNIX%20%E8%AF%AD%E6%B3%95%EF%BC%88%E5%92%8C%E5%85%B6%E4%BB%96%E9%94%99%E8%AF%AF%EF%BC%89.png)
else
运行此脚本时,仅第 49 行出现语法错误。谁能指出为什么?不让我运行我的脚本。我的删除脚本代码以及我的脚本应该具有的内容如下:
脚本必须测试 rm 命令并显示与 rm 命令相同的错误消息
脚本名称已删除。在脚本中创建“已删除”回收站目录。
在 $HOME 中创建一个名为 .restore.info 的隐藏文件。该文件的每一行将包含已删除目录中的文件名,后跟冒号,然后是文件的原始完整路径
删除目录中的文件名格式为“filename_inode”
确保脚本可以删除多个文件和通配符
测试 -i(交互式)和 -v(详细)的命令行参数
1 #/bin/bash
2
3 function directory(){
4 if [ ! -d ~/deleted }
5 then
6 mkdir ~/deleted
7 fi
8 if [ ! -f ~/.restore.info ]
9 then
10 touch ~/.restore.info
11 fi
12 }
13
14 function movefile(){
15 mv $1 ~/deleted/$1
16 echo "file moved to recycle bin"
17 }
18
19 function error_conditions(){
20 #prints error messages and checks if file is in project directory
21 if [ ! -f ~/project ]
22 then
23 echo "cannot remove $filename: no such file or directory"
24 elif [ -d ~/project ]
25 then
26 echo "cannot remove $filename: is a directory"
27 else
28 echo "missing operand"
29 fi
30 }
31
32 function delete_file(){
33 #gets inode for filename
34 inode=$(stat -c%i $filename)
35 filename=$1
36 pwd=$(readlink -e$filename)
37 if $interactive
38 then
39 if [ $verbose = true ]; then
40 read -p "Are you sure you want to delete $filename?" i_input
41 if [ $i_input == "y" ] || [ $i_input == "Y" }
42 then
43 mv $filename ~/delete/${filename}_inode
44 echo ${filename}_$inode:$pwd>>~/.restore.info
45 echo "$filename has been deleted"
46 else
47 echo "Nothing has been deleted"
48 fi
49 else
50 read -p "Are you sure you want to delete $filename?" i_input
51 if [$i_input == "y" ] || [ $i_input == "Y" ];
52 then
53 mv $filename ~/deleted/${filename}_$inode
54 echo ${filename}_$inode:$pwd>>~/.restore.info
55 else
56 echo Aborted
57 fi
58 fi
59 elif $verbose
60 then
61 mv $filename ~/deleted/${filename}_inode
62 echo ${filename}_$inode:$inode:pwd>>~/.restore.info
63 echo "$filename has been deleted."
64 else
65 mv $filename ~/deleted/${filename}_$inode
66 echo ${filename}_$inode:$pwd>>~/.restore.info
67 echo Executed
68 fi
69 }
70 interactive=false
71 verbose=false
72 recursive=false
73 while getopts iv option
74 do
75 case $option in
76 i) interactive=true;;
77 v) verbose=true;;
78 esac
79 done
80 shift $[OPTIND-1]
81 for i in $*
82 do
83 filename=$i
84 baseline=$(basename $i)
85 if [ "$i" == "" ];
86 then
87 echo "No filename provided"
88 elif [ -d $filename ];
89 then
90 if [ ! $recursive = true ];
91 then
92 echo "Directory name provided, please provide a file"
93 fi
94 elif [ ! -f $filename ];
95 then
96 echo "File does not exist"
97 elif [ "$basefule" == "safe_rm" ]
98 then
99 echo "Attempting to delete safe_rm"
100 else
101 delete_file $filename
102 fi
103 done
104
105 #################################M A I N###############################
106 directory
107 error_conditions $*
108 delete_file $*
109 move_file $r
答案1
第 41 行有一个错误的右括号