simple while loop in bash
bash, linux, while-loop
Solution
Add spaces.
while [ $x -lt 10 ];
For more information, please see this answer to How to use double or single bracket, parentheses, curly braces:
A single bracket (`[`) usually actually calls a program named `[`; `man test` or `man [` for more info. Example:
$ VARIABLE=abcdef
$ if [ $VARIABLE == abcdef ] ; then echo yes ; else echo no ; fi
yes
Also, this is what `info test` has to say on the matter:
'`test`' has an alternate form that uses opening and closing square brackets instead a leading '`test`'. For example, instead of '`test -d /`', you can write '`[ -d / ]`'. The square brackets must be separate arguments; for example, '`[-d /]`' does not have the desired effect. Since '`test EXPR`' and '`[ EXPR ]`' have the same meaning, only the former form is discussed below.
Therefore, the equivalent would look like:
let x=5; while test $x -lt 10;do echo "x is : $x";let x=$x+1; done
Problem
I've started learning bash scripting. I wrote simple while loop, but it doesn't work. it's say that : command not found.does anybody knows why ? Here is my code: ``` let x=5; while [$x -lt 10];do echo "x is : $x";let x=$x+1; done ```