I am currently try to learn the linux operating system as well as some bash programming. I have come across some online course work which has been very helpful, I have been working through some assignments and since I have no teacher to ask I have come to you experts.
So the program I am trying to write, asks the user to input a username and password. I have 3 combos that I came up with, and when a user gets them right you get a welcome. When you get it wrong I want it to loop for them to try again.
I can do this when it is just one variable, say enter password. But I am not sure how to do this when you have a username and password and you then want to verify against stored variables. Please excuse me if my english isnt the best at explaining.
Here is my code so far.
#!/bin/bash
user1=Jill
user2=Bob
user3=Jim
pass1=Apple
pass2=Orange
pass3=Lemon
echo ""
echo -n "Username: "
read USER
echo -n "Password: "
read PASS
if [ "$USER" = "$user1" ] && [ "$PASS" = "$pass1" ]; then
echo "Congrats your in"
elif [ "$USER" = "$user2" ] && [ "$PASS" = "$pass2" ]; then
echo "Congrats your in"
elif [ "$USER" = "$user3" ] && [ "$PASS" = "$pass3" ]; then
echo "Congrats your in"
else
echo "Please Try Again"
read USER
read PASS
fi
exit 0
So I know that it is not correct, as any incorrect combo u enter wont let you try again to input ur choice. But I do not understand why? Could someone shed some light on this for me. I have looked at many resources and have not been able to answer.