Bash script that exits when user supplies particular input

I'm trying to write a script that shows a question to the user: "Are you boring yet? (1=Yes; 2=No)". The script should run until the user hits 2. I am new to Bash and so far I've spent around 6 hours writing this script:

#!/bin/bash
echo "Are you boring yet ? No = 1 , Yes = 2"
read $1
if [[ $1 -eq 1 ]]
then
echo "Are you boring yet ? No = 1 , Yes = 2"
read $2
if [[ $2 != 2 ]]
then
break
fi
fi

But whether I press 1 or 2 it has the same output for closing it.

Any ideas how to make the script correctly?


Solution 1:

Add a while loop and you only need to ask the question once. As long as you keep pressing 1 it will loop over and over until 2 is pressed, then break is called to exit the loop. Also, just use a name for assigning variables, then use $name to call the variable. I used junk for the example.

#!/bin/bash

while true
do
    echo "Are you bored yet? No = 1, Yes = 2"
    read junk
    if [[ $junk -eq 2 ]]; then
        break
    fi
done