天天看点

提示用户输入一个用户名,判断是否存在,如果存在显示该用户的shell

vim shell.sh

read -p "please input a username:" MYUSER

if cut -d: -f1 |grep "^$MYUSER$" /etc/passwd &>/dev/null

then

MYSHELL=`grep "^MYUSER" /etc/passwd | cut -d: -f7 `

echo "${MYUSER}'s shell is $MYSHELL"

else

echo "$MYUSER is not exist"

fi

本文转自 张玉坡 51CTO博客,原文链接:http://blog.51cto.com/fighter/462778