标签:shell
写一个脚本:
1、提示用户输入一个用户名
2、显示一个菜单给用户。形如
U|u show UID
G|g show GID
S|s show SHELL
Q|q quit
3、提醒用户选择一个选项,并显示其所有选择的内容
如果用户给一个错误的选项,则提醒用户选项错误,请其重新选择
#!/bin/bash # echo "* * * * * * * * * * * * *" read -p "Please enter your user name: " US until [ $US == ‘quit‘ ];do if id -u $US &> /dev/null;then echo "$US is OK!Please select" echo "=======options=======" cat << EOF U|u) show UID G|g) show GID S|s) show SHELL q|Q) quit EOF echo "=====================" read -p "Please select options: " SH echo "=====================" while : ;do case $SH in U|u) echo "$US uid=`grep "^$US" /etc/passwd | cut -d: -f4`" ;; G|g) echo "$US gid=`grep "^$US" /etc/passwd | cut -d: -f3`" ;; S|s) echo "$US shell=`grep "^$US" /etc/passwd | cut -d: -f7`" ;; Q|q) echo "******quiting...******" exit ;; *) echo "Wrong option.Please again" echo "=======options=======" cat << EOF U|u) show UID G|g) show GID S|s) show SHELL q|Q) quit EOF echo "=====================" ;; esac read -p "Please choose again: " SH done else echo "-------------------------------------" echo "The user name wrong.." echo "* * * * * * * * * * * * *" read -p "Please enter the username again : " US fi done
标签:shell
原文地址:http://10957607.blog.51cto.com/10947607/1859465