现在的位置: 首页 > 综合 > 正文

实现一个让用户输入不超过3次的程序,直到输入正确的值

2019年05月05日 ⁄ 综合 ⁄ 共 245字 ⁄ 字号 评论关闭
#/bin/bash count=3 while :;do read -p "username:" username echo "input username is $username" if [[ $username != "haha" ]];then #如果输入的不是预定的值则 ((count--)) #计数器减一 echo "Error! try $count" #显示提示信息 ((count==0))&&break||continue #当次数用完的时候则循环结束否则循环继续 else break #当输入正确的时候,跳出循环 fi done

抱歉!评论已关闭.