判断用户是否存在,如果存在就显示其UID及Shell

#!/bin/bash
#
function user {
judge=`id -u $1 &>/dev/null`
if [ $? -eq 0 ];then
uid=`id -u $1`
Shell=`grep "$1" /etc/passwd | awk -F : '{print $7}' `
echo -e "33[32mUser is UID $uid Shell is $Shell.33[0m"
return 0
else
echo -e "33[31mUser is no such33[0m"
return 1
fi
}
while :;do
read -p "input username or quit :" choice
if [ $choice == 'quit' ];then
echo -e "33[33mQuit...33[0m"
break
else
user $choice
fi
done

原文地址:https://www.cnblogs.com/sjie0224/p/6840893.html