Bash while loop error -
this question has answer here:
this simple school project. console keeps stating [5:command not found
#!/bin/bash num=28 echo "guess number number between 1 , 100" read guess while [$guess -ne $num] if [$guess -lt $num] echo "number higher" elif [$guess -gt $num] echo "number lower" else echo "correct! number $number" fi done
while [$guess -ne $num]
is interpreted first expanding parameters:
while [5 -ne 28]
which causes command [5
executed, passing arguments -ne
, 28]
you wanted execute command [
, needed write:
while [ $guess -ne $num ]
(note spaces around both [
, ]
. without space, characters become part of word.)
ditto statements following if
, elif
.
Comments
Post a Comment