0

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
2
  • 1
    You seem to be missing the beginning of your loop. Also, it's not clear where you're setting values for $Admin and $Secret. Commented Jun 6, 2022 at 23:28
  • @Steven : There is no loop in your code. Please post the complete code. I also suggest to paste your program into [shellcheck](shellcheck.net), before asking here such a question. Commented Jun 7, 2022 at 7:16

1 Answer 1

1

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!"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.