#/bin/bash#debug=0add=0del=0rm=0while [$#-gt 0]docase $ in-v|-verbose] debug=1shift;; -H|--HELP) #帮助文档echo "' basename $ '--add list--del list-h|--help--rm list" Exit 0;; --add) #添加用户ADD =1adduser=$2shift 2;; --del) #删除用户DEL =1deluser=$2shift 2;; --RM) #删除文件RM = 1; Rmfile=$2shift 2;; *) echo "wrong" shift; Esacdoneif test $RM-eq 1;then# $RM = 1, the--RM command is selected, Rmfile is the required action file after--rm. For I in ' echo $RMFILE | Sed ' s/,//g ';d o#sed ' s/,//g ' or ' [email protected],@ @g ' will rmfile inside the ', ' remove, as you may delete multiple files. If Test-e $I; then#-e determines if the file exists, then-f is the generic file,-D is the directory file. [-F $I] && rm-r $I [-D $I] && rm-rf $I [$DEBUG-eq 1] && echo "Delete this file successfully" else[$DEBUG-eq 1] && Echo ' The file does not exist! ' Fi donefiif test $ADD-eq 1;thenfor I in ' echo $ADDUSER | Sed ' s/,//g ';d OIF ID $I &>/dev/null;then[$DEBUG-eq 1] && echo "User name is $i user already exists and cannot be added as a new user" Elsesudo Useradd $I [$DEBUG-eq 1] && echo "New user $i Add Success" Fidonefiif test $DEL-eq 1;thenfor I in ' echo $DELUSER | Sed ' s/,//g ';d OIF ID $I &≫/dev/null;thensudo Userdel $I [$DEBUG-eq 1] && echo "Delete $i user Success" else[$DEBUG-eq 1] && echo "User $i not present, Cannot delete "Fidonefi
Shell Script Add user Delete user Delete file script implementation