#!/bin/bash
#功能:循环读取客户端输入的用户及密码,判断是否为root,密码为123456,可以尝试3次,而后自动退出.
#作者:liusingbon
for i in {1..3}
do
read -p "请输入用户" user
read -p "请输入密码" password
if [ $user == "root" ]&&[ $password -eq 123456 ];then
echo "登录成功"
exit
else
echo"用户名或密码错误,你还有2次登录机会"
fi
done
#使用while循环
#!/bin/bash
i=1 //初始赋值
while [$i -le 3]
do
read -p "请输入用户" user
read -p "请输入密码" password
if [ $user == "root" ]&&[ $password -eq 123456 ];then
echo "登录成功"
exit
else
echo"用户名或密码错误,你还有2次登录机会"
fi
let i++ //自加1,进入下一次循环
done