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
测试结果
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容