loop question

hey guys what im trying to do is do a simple script that will ask for a password and on the 5th time it says access denied if the right password is still not entered this is what i have so far can anyone help me im not good with scripting
thanks in advance

 #!/bin/bash
secretname=secret
name=noname
echo "try to guess the password."
echo
until [ "$name" = "$secretname" ]
do
   echo -n "your guess: "
   read name
echo "very good."
done

Pretty good first try.

#!/bin/bash
secretname=secret
name=noname
echo "try to guess the password."
TRY=0
echo
until [ "$name" = "$secretname" ] || [ "$TRY" -ge 5 ]
do
        echo -n "your guess: "
        read name
        ((TRY++))
done

if [ "$name" = "$secretname" ]
then
        echo "You guessed!"
else
        echo "Fail"
fi
1 Like

ty corona how long u been doing scripts