Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Breaking out of bash loop when condition is met

Hey guys, I'm trying to figure out how to break out of a loop when the user types the correct username. For now my loop continues to give me the same "Try again" output even when the condition is correct. I tried with 2 loops but it didn't work. Any ideas?
Code
if [ "$userResult" == 1 ]
then
echo Enter password:
read password
else
echo Wrong username. Try again:
read username
while [ "$userResult" == 0 ]
do
echo try again:
read username
done
fi
When username is correct the first time:
Code
Enter Username
BOBO
Enter password:
When username is correct the 2nd time:
Code
Enter Username
B
Wrong username. Try again:
BOBO
try again:
Code
#!/bin/bash
echo -n "please type your name: "
read name
while [ "$name" != "sunjester" ]
do
        read name
        echo -n "please type your name: "
done

still buggy but have fun.
http://sunjester.rf.gd - proxies, logins, scanner results
(Oct 18, 2019 02:13 AM)realsunjester Wrote:  
Code
#!/bin/bash
echo -n "please type your name: "
read name
while [ "$name" != "sunjester" ]
do
       read name
       echo -n "please type your name: "
done

still buggy but have fun.

It doesn't work in my case as the username that is being read is either a 1 or a 0 (output from mysql). Basically if the user is found in the database return 1, else 0.

(Oct 18, 2019 04:45 AM)friiz1337 Wrote:  It doesn't work in my case as the username that is being read is either a 1 or a 0 (output from mysql). Basically if the user is found in the database return 1, else 0.

Fixed it by using a function that calls the username. If anyone is also interested in knowing how to fix this problem, PM me.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by .eXeDec 2, 2019 09:58 PM 1 361 Dec 2, 2019 09:58 PM
Last Post: Thomas Saison
[Python] by datguy.devFeb 23, 2019 05:19 PM 0 123 Feb 23, 2019 05:19 PM
Last Post: datguy.dev
[Java] by ohxerxeFeb 4, 2018 03:26 PM 3 302 Feb 4, 2018 03:26 PM
Last Post: matt