shell模拟注册流程

#---------------------模拟注册流程------------------------------
#read:-p提示语句 -t等待时间 -n字符个数 -s默读
#if-else流程控制语句,注意关键词:if,then,else,fi
#case语句,注意每个条件后的两个分号
#if后添加判断条件,注意空格
#printf格式化输出语句,注意需要显式化换行
#echo -e 处理转义字符 -n 不换行
#---------------------------------------------------------------
if read -t 5 -n1 -p "Do you want to register a count[Y/N]?" answer
then
    case $answer in
        Y|y)
            echo -e "\n"
            read -p "what is your name:" name
            printf "\n"
            read -s -p "input your password:" pw
            echo -e "\n"
            read -s -p "repeat your password:" repw
            if [ $pw == $repw ]
            then
                printf "\n success\n"
            else
                printf "\nthe password doesn't equal to the repassword:\n"
                printf "\n %s  %s\n" $pw $repw
            fi
        ;;
        N|n)
            printf "\n ok,good bye\n";;
        *)
            printf "\n error choice\n";;
     esac
else
    echo "sorry , too slow"
fi
shell模拟注册流程_第1张图片
测试结果

你可能感兴趣的:(shell模拟注册流程)