[root@localhost ~]# ! /bin/bash
case "$1" in
[root@localhost ~]# case "$1" in
> start)
> echo "Starthing ABC service"
> ;;
> stop)
> echo "Stop ABC service"
> ;;
> force-relonad|restart)
> $0 stop
> $0 start
> ;;
> status)
> echo "Display status of ABC service"
> ;;
> *)
> echo "Usage: $0 {start|stop|restart|force-reload|status}"
> exit 1
> ;;
> esac
Usage: /bin/bash {start|stop|restart|force-reload|status}
exit
[root@localhost ~]# if [ $# = 0 ]
> then
> echo "Usage: $0 : <number>"
> else
> count=$l
> while [ $count -gt 0 ]
> do
> count=`expr $count -l`
> echo -e "\015 $count \c"
> sleep l
> done
> fi
Usage: sh : <number>
[root@localhost ~]# get_attr()
> {
> while true
> do
> echo -e "$2 [$3] : \c"; read val
> [ "$val" = "" ] && val=$3
> for i in $4
> do
> [ "$val" = "$i" ] && break 2
> done
> echo -e "**** Invalid choice \"$val\", must be in \"$4\""
> eval "$1=$val
> }
> [root@localhost ~]# get_attr COLOR "Color of the box" white \
> > "red green pink white black"
Color of the box [white] : red
[root@localhost ~]# get_attr DAY "Day of the week" mon \
> "sun mon tue wed thu fri sat"
Day of the week [mon] :
[root@localhost ~]# get_attr ROLE "Your role in the system" student \
> "admin student tescher guest"
Your role in the system [student] : echo "COLOR=$COLOR DAY=$DAY ROLE=$ROLE"
**** Invalid choice "echo "COLOR=$COLOR DAY=$DAY ROLE=$ROLE"", must be in "admin
student tescher guest"
来源:CSDN
作者:小墨黑
链接:https://blog.csdn.net/lj15847090684/article/details/103657583