首页 > 代码库 > shell学习题
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学习题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。