判断用户是否存在,如果存在就显示其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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM