最近学了不少shell的知识,就写了个玩具玩玩

#!/bin/bash
#author joe
check_user(){
if id $1 &>/dev/null;then
echo "the user is $1"
return 0
else
echo "$1 is not exist"
return 3
fi
}
menu(){
case $1 in
u|U)
echo "the user $2  uid is `grep "$2" /etc/passwd |cut -d: -f3`"
;;
g|G)
echo "the user $2 gid  is `grep "$2" /etc/passwd |cut -d: -f4`"
;;
s|S)
echo "the user $2  shell is `grep "$2" /etc/passwd |cut -d: -f7`"
;;
q|Q)
break
;;
*)
echo "the error insert,please try again"
return 5
;;
esac
}
check_blank(){
username=$1
while :
do
if [ "$username" != "" ];then
break
else
read -p "insert a user name:" username
continue
fi
done
}
read -p "insert a user name:" username
check_blank $username
until [ $username == "q" -o $username == "Q" ];
do
check_user $username
if [ $? == 3 ];then
read -p  "do you want create the new user:?" answer
if [ "$answer" == "y" ];then
useradd $username
else
echo "----------------------------------"
read -p "insert a user name:" username
check_blank $username
continue
fi
fi
while :
do
echo "MENU"
echo "u|U)---show UID"
echo "g|G)---show GID"
echo "s|S)---show shell"
echo "q|Q)---quit"
read -p "insert your choice:" choice
menu $choice $username
if [ $? == 5 ];then
sleep 1
clear
continue
fi
read -p "do you want to continue:" answer_1
if [ "$answer_1" == "y" ];then
clear
else
break
fi
done
echo "------------------------------------"
read -p "insert a user name:" username
check_blank $username
done