Just started using UNIX, im at the basics and my scripts broken.

echo "Hi $username, guess what my favourite colour is!"
count=0
while [[ $count -ne 1 ]] 
    do
                read colour
        if ["$colour" -eq "forget it"]
        then
            $count=1
            echo "See ya later!"
        elif ["$colour" -eq "watermelon"]
        then
            $count=1
            echo "You guessed correctly! Great job!"
        fi
        echo "try again or write forget it to give up"
done

Heres the script for a guessing game, for some reason it reads $colour as a literal when i pass it through the while loop and gives me errors like:

(if i passed in red for $colour)

[red: command not found

Why is it doing this???!

try using "count=1" not "$count=1". Also, include spaces around square brackets.

1 Like

Insert a space after the opening bracket [ and before the closing bracket ].

1 Like

Didn't work, now its giving me this error when i pass in red

[: red: integer expression expected

eq is for numeric comparison, use = instead:

[ "$colour" = "forget it" ] ...
1 Like

Replace -eq with = for string comparison.

1 Like

Awesome! thanks a lot!

All fixed!