码迷,mamicode.com
首页 > 系统相关 > 详细

linux shell命令之脚本要有足够的提示

时间:2021-04-14 11:41:38      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:登录   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

linux shell命令之脚本要有足够的提示

标签:登录   username   错误   用户   read   NPU   l命令   hat   密码   

原文地址:https://www.cnblogs.com/zhudaheng123/p/14652778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!