我创建了一个脚本,该脚本可以帮助管理员从文本文件中添加和删除用户,而不是手动进行操作。我遇到了这个错误,我无法解决它。
[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'
我该如何解决该错误?
#!/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行之间if
和之间添加一个空格。[
您的代码应像这样。
#!/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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句