繁体   English   中英

如何在 shell 脚本中进行 while 循环验证

[英]how to make a verification while loop in shell script

我想问你一个关于 while 循环的问题。 我看过前夕

#!/bin/bash
# Username and password loop;do
 
       
        fi
done

我不确定我是否完全理解你的问题,但似乎你是真的失踪了while true; do while true; dobreak命令:

#!/bin/bash

Admin="the_admin_user"
Secret="the_secret_password"

while true; do
    read -p "Please Enter Username  : " Username
    if [[ "$Username" = "$Admin" ]]
    then
        echo "Username is Correct"
        break
    else
        echo "Username is Wrong"
    fi
done

while true; do
    read -p "Please Enter Password  : " Password1
    read -p "Enter Password Again   : " Password2

    if [[ "$Password1" != "$Password2" ]]
    then
        echo "Passwords don't match! Try again."
    elif [[ "$Password1" = "$Secret" ]]
    then
        echo "Password is Correct"
        break
    else
        echo "Password is Wrong"
    fi
done

echo "Success!"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM