[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]# 

 

相关文章:

  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2021-12-19
  • 2021-05-29
  • 2021-10-13
猜你喜欢
  • 2022-12-23
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2021-09-14
  • 2022-12-23
相关资源
相似解决方案