shell脚本,提示用户输入一个用户名,如果存在;显示用户UID和SHELL信息;否则,则显示无此用户;显示完成之后,提示用户再次输入;如果是quit则退出;

[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]# 
原文地址:https://www.cnblogs.com/wangyuebo/p/5836019.html