syntax error near unexpected token `then'
本问题已经有最佳答案,请猛点这里访问。
我创建了一个脚本,帮助管理员从文本文件中添加和删除用户,而不是手动执行。我遇到这个错误,解决它有困难。
1 2 3 | [ec2-user@ip-172-31-15-55 ~]$ ./account-manager user add ./account-manager: line 21: syntax error near unexpected token `then' ./account-manager: line 21: ` then' |
如何修复此错误?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #!/bin/bash file=$1 action=$2 if [ -z"$file" ] then echo" Please enter a file with your users" exit 0 fi if [ -z"$action" ] then echo" Please define an account to remove or deleete" exit 0 fi for user in `cat $file` do if["$action" =="add" ] then echo adding user: $user useradd $user -m -p password fi if["$action" =="remove" ] then echo removing user: $user userdel -r $user fi done |
号
您应该在第20行和第25行的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #!/bin/bash file=$1 action=$2 if [ -z"$file" ] then echo" Please enter a file with your users" exit 0 fi if [ -z"$action" ] then echo" Please define an account to remove or deleete" exit 0 fi for user in `cat $file` do if ["$action" =="add" ] then echo adding user: $user useradd $user -m -p password fi if ["$action" =="remove" ] then echo removing user: $user userdel -r $user fi done |
注意你的