[root@localhost wyb]# cat tishiuser.sh #!/bin/bash #提示用戶輸入一個用戶名,如果存在;顯示用戶UID和SHELL信息;否則, #則顯示無此用戶;顯示完成之后,提示用戶再次輸入;如果是quit則退出; echo 'Input `quit` to quit' while : do read -p "Please Input a user:" choice [ -z $choice ] &&continue [[ "$choice" = "quit" ]] && break id $choice &> /dev/null [ $? -eq 0 ] && grep "$choice" /etc/passwd|awk -F ":" '{print $3,$NF}'|| echo "NO this user!" done [root@localhost wyb]# bash tishiuser.sh Input `quit` to quit Please Input a user:quit [root@localhost wyb]# bash tishiuser.sh Input `quit` to quit Please Input a user:root 0 /bin/bash 11 /sbin/nologin Please Input a user:fineday 500 /bin/bash Please Input a user:bobo 501 /bin/bash Please Input a user:quit [root@localhost wyb]# bash tishiuser.sh Input `quit` to quit Please Input a user:llkk NO this user! Please Input a user:quit [root@localhost wyb]#