Q:

While loop does not end when condition is met

I am trying to make a horse betting game that runs in bash
I copied the gpio library to ubuntu from raspbian 
The while loop Does not end when $BET is not 0
BET=0
while [ $BET=0 ]
do
    if [ $(gpio read 21) -eq 1 ]
        then
            BET=1
    elif [ $(gpio read 22) -eq 1 ]
        then
            BET=2
    elif [ $(gpio read 23) -eq 1 ]
        then
            BET=3
    elif [ $(gpio read 24) -eq 1 ]
        then
            BET=4 
    elif [ $(gpio read 25) -eq 1 ]
        then
            BET=5
    else
        echo "" > /dev/null 
    fi
    echo $BET
done

Why does this not work? Thanks in advance

A:

You're missing some white-space: [ $BET=0 ] should be [ $BET = 0 ] instead. Better yet, perform a numerical comparison with [ $BET -eq 0 ].
See man test for the difference between the three.
P.S.: Run shellcheck (from the eponymous package) to help you spot potential flaws and issues in shell scripts. For your script it prints:
In - line 2:
while [ $BET=0 ]
        ^-- SC2077: You need spaces around the comparison operator.

In - line 4:
    if [ $(gpio read 21) -eq 1 ]
         ^-- SC2046: Quote this to prevent word splitting.

In - line 7:
    elif [ $(gpio read 22) -eq 1 ]
           ^-- SC2046: Quote this to prevent word splitting.

In - line 10:
    elif [ $(gpio read 23) -eq 1 ]
           ^-- SC2046: Quote this to prevent word splitting.

In - line 13:
    elif [ $(gpio read 24) -eq 1 ]
           ^-- SC2046: Quote this to prevent word splitting.

In - line 16:
    elif [ $(gpio read 25) -eq 1 ]
           ^-- SC2046: Quote this to prevent word splitting.

