Error in while loop

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

I am getting the following error while executing for while loo:

count: command not found
[: -le: unary operator expected

  1. Relevant commands, code, scripts, algorithms:

I have created the following code lines:

#!/bin/sh
count =1
while [ $count -le 10 ]
do
echo $count
count = `expr $count + 1`
done

  1. The attempts at a solution (include all code and scripts):

Wrote the above code.

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Amity, Noida, India, Prof. Sanjeev Thakur, MCA

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Error due to additional spaces b/w count variables .. Corrected one below

#!/bin/sh
count=1
while [ $count -le 10 ]
do
echo $count
count=`expr $count + 1`
done

Thanks for the reply

Still getting the following error msg:

./while_loop.ksh_new: line 3: count: command not found
./while_loop.ksh_new: line 5: [: -le: unary operator expected

cat ./while_loop.ksh_new
#!/bin/sh
count =1
while [ $count -le 10 ]
do
echo $count
count=`expr $count + 1`
done
bash-3.2$

again u have given additional space while assigning value to a varaible count =1 .. Try to use the code which i have corrected ..

Worked now..Thanks a lot for the quick help.. :slight_smile: