标签:登录 username 错误 用户 read NPU l命令 hat 密码
一个有参数但无提示说明的脚本
#login1.sh: 用户登录,判断用户输入的用户名和密码是否错误
vi login1.sh
#!/bin/bash
for ((i=0; i < 3; i++))
do
read username
read password
if test "$username" = "user" -a "$password" = "pwd"
then
echo "login success"
flag=1;
break;
fi
done
./login1.sh
^C
一个有参数且有提示说明的脚本
#login2.sh:用户登录,判断用户输入的用户名和密码是否正确
vi login2.sh
#!/bin/bash
flag=0;
#提示该脚本的用途
echo "This script is used to username and password what you input is right or wrong."
#for 循环用于提示输入用户名和密码,并判断正误
for ((i=0; i < 3; i++))
do
echo -n "Please input your name:"
read username
echo -n "Please input your password: "
read password
if test "$username" = "user" -a "$password" = "pwd"
then
echo "Login success"
flag=1
break
else
echo "The username or password is wrong. Try again! "
fi
done
#三次输入不正确,提示用户退出脚本
if [ "$flag" -eq 0 ]
then
echo "You have tried 3 times. login fail!"
fi
./login2.sh
This script is used to username and password what you input is right or wrong.
Please input your name:alloy
Please input your password: 123
The username or password is wrong. Try again!
Please input your name:user
Please input your password: pwd
Login success
标签:登录 username 错误 用户 read NPU l命令 hat 密码
原文地址:https://www.cnblogs.com/zhudaheng123/p/14652778.html