写一个脚本:
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: " USuntil [ $US == 'quit' ];doif id -u $US &> /dev/null;thenecho "$US is OK!Please select"echo "=======options======="cat << EOFU|u) show UIDG|g) show GIDS|s) show SHELLq|Q) quitEOFecho "=====================" read -p "Please select options: " SHecho "=====================" 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 << EOFU|u) show UIDG|g) show GIDS|s) show SHELLq|Q) quitEOFecho "=====================" ;; esacread -p "Please choose again: " SHdoneelse echo "-------------------------------------" echo "The user name wrong.." echo "* * * * * * * * * * * * *" read -p "Please enter the username again : " US fidone