判断用户是否存在,如果存在就显示其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 "\033[32mUser is UID $uid Shell is $Shell.\033[0m"
return 0
else
echo -e "\033[31mUser is no such\033[0m"
return 1
fi
}
while :;do
read -p "input username or quit :" choice
if [ $choice == 'quit' ];then
echo -e "\033[33mQuit...\033[0m"
break
else
user $choice
fi
done

posted @ 2017-05-11 14:50  孤鸟的悲歌丶  阅读(3882)  评论(0编辑  收藏  举报