how to make a verification while loop in shell script

I'd want to ask you a question concerning a while loop. I've looked eve

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

Upvotes: 0

Views: 93

Answers (1)

glenn jackman
glenn jackman

Reputation: 246847

I'm not sure I entirely understand your question, but it seems that you're missing while true; do and the break command:

#!/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!"

Upvotes: 1

Related Questions