判断输入用户名是否存在

 

 
  
  1. #!/bin/bash 
  2. echo "Please input username:" 
  3. read username 
  4. grep "$username" /etc/passwd > /dev/null 
  5. if [ $? -eq 0 ] 
  6.   then  
  7.       echo "The user is exist." 
  8.   else 
  9.       echo "The user is no exist." 
  10. fi