Practice One:
1, receive the parameter, prompt input parameter is what type:
#!/bin/bash
#program:
#接收参数并输出参数类型
#history Donggen 2016-10-27-17:20
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bansh
Export PATH
Case $ in
[[:d Igit:]])
echo "It is Digit"
;;
[[: Lower:]])
echo "It is Lower"
;;
[[: Upper:]])
echo "It is Upper"
;;
*)
echo "It is Unknown"
;;
Esac
Exercise two:
2, write a script, you can accept the options and parameters, and then get each option, and the parameters of the options;
And can be based on options and parameters to make a specific operation. Like Administrators.sh-add Tom,jerry--del Tom,blair
-v|--verbose-h|--help
#!/bin/bash
#program:
#练习接收参数, and get the parameters
#history Donggen 2016-10-27-22:40
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bash
Export PATH
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
Addusers=$2
Shift 2
;;
--del)
Del=1
Delusers=$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 the USER in ' echo $ADDUSERS |sed ' [email protected],@ @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 the USER in ' echo $DELUSERS |sed ' [email protected],@ @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 exist."
Fi
Done
Fi
This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1866544
Linux Command exercise: Case selection Structure Statement exercise