Write a script that can combine the options and parameters, then get each option, and the parameters of the options, and can be based on options and parameters to make a specific operation, such as :adminusers.sh--add Tom,blair- -del Tom,blair-v|--verbose-h|--help
#!/bin/bash
#
Debug=0
Add=0
Del=0
For i in ' seq 0 $# '; Do
If [$#-gt 0]; Then
Case $ in
-v|--verbose)
Debug=1
shift;
-H|--HELP)
echo "Usage: ' basename $--add user_list--del user_list-v|--verbose-h|--help"
Exit 0;;
--add)
Add=1
Adduser=$2
Shift 2;;
--del)
Del=1
Deluser=$2
Shift 2;;
*)
echo "Usage: ' basename $--add user_list--del user_list-v|--verbose-h|--help"
Exit 7;;
Esac
Fi
Done
If [$ADD-eq 1]; Then
For USER in ' echo $ADDUSER | Sed ' s#,# #g '; Do
If ID $USER &>/dev/null; Then
[$DEBUG-eq 1] && echo "$USER exists"
Else
Useradd $USER
[$DEBUG-eq 1] && echo "ADD user $USER finished"
Fi
Done
Fi
If [$DEL-eq 1]; Then
For USER in ' echo $DELUSER | Sed ' s#,# #g '; Do
If ID $USER &>/dev/null; Then
Userdel-r $USER
[$DEBUG-eq 1] && echo "Delete $USER finished"
Else
[$DEBUG-eq 1] && echo "$USER NOT EXISTS"
Fi
Done
Fi
16.03.18 the use of "practice" case Write a script