#!/bin/bash # if [ $# -lt 1 ];then echo "Aadminuser ARG ..." exit 8 fi if [ $1 == "add" ];then for I in {1..10};do if id user$I &> /dev/null; then echo " user user$I exist" else useradd user$I echo "user$I" | passwd --stdin user$I &> /dev/null echo "user$I finished" fi done elif [ $1 == "del" ];then for I in {1..10};do if id user$I &> /dev/null;then userdel -r user$I echo "user$I delete finished" else "user$I not exists" fi done else echo "Unknown ARG" exit 9 fi
#!/bin/bash # if [ $1 = ‘--add‘ ];then for I in `echo $2 | sed ‘s/,/ /g‘`;do if id $I &> /dev/null;then echo "user $I exist" else useradd $I echo "$I" | passwd --stdin $I &> /dev/null echo "user $I Add finished" fi done elif [ $1 = "--del" ];then for I in `echo $2 | sed ‘s/,/ /g‘`;do if id $I &> /dev/null;then userdel -r $I echo "user $I Del finished" else echo "user $I not exist" fi done elif [ $1 = "--help" ];then echo " Help Usage --add or --del" else echo "Unknown options" fi
组合测试条件:
-a 逻辑与
-o 逻辑或
! 非关系,取反
if [ $# -gt 1 -a $# -le 3 ] 大于1小于3
if [ $# -gt 1] && [ $# -le 3 ] 大于1小于3
#!/bin/bash # if [ $1 == ‘q‘ -o $1 == ‘Q‘ -o $1 == ‘quit‘ -o $1 == ‘Quit‘ ];then echo "Quitting...." else echo "Unknown Argument" exit 0 fi
原文:http://leozhenping.blog.51cto.com/10043183/1632962