#!/bin/bash str=wgw for ((i=1;i<=3;i++)) do read -p "请输入密码: " nb if [ ${nb}a = ${str}a ];then echo "密码输入正确" break else echo "密码输入错误。第$i次机会" fi done