Click to See Complete Forum and Search --> : syntax error requarding the command "do"


supercoffee
11-16-2003, 09:23 AM
when I try to write a simple sscript

x=0
while [ $x -lt 10 ] ;
do
echo $x
x=`expr $x + 1`
done

when i run the file, it show
line 1: 0: command not found
line 2: [:-lt:unary operator expected

I am using redhat 8
What's the problem of the above script? Thanks!

pickarooney
11-16-2003, 10:05 AM
which shell are you using?
I cut and paste that script, ran it and it worked fine (bash shell).

andycrofts
11-16-2003, 10:28 AM
Hi
I tried it, and entering it exactly as you've posted it, it works fine.
However, I can replicate your problem by having
x= 0
rather than
x=0

Then I get:-
[andy@madetoja andy]$ ./ex
./ex: line 2: 0: command not found
./ex: line 3: [: -lt: unary operator expected
[andy@madetoja andy]$

I suggest what you've entered isn't what you've got...But if it looks exactly the same, I guess you've got a non-printable character between = and 0. Retype the line.

Incidentally, I put
#!/bin/bash
at line 1 - which is why your line numbers are one less than mine...

andycrofts
11-17-2003, 11:09 AM
..might have been nice to know what the fix was.