Simple looping in shell

Hii all.
I have a problem with my shell script.
This is my code

while [ $count -le 13526 ]
do
    space.exe inputs/gr$count >> outputs/t$count
    count=$[$count+1]
done

I ussually work in cygwin. When i tried in linux(ubuntu, kali linux) i found error said

Syntax error : end of file unexpected (expecting "do")

Need a really fast help for that :). Thank you..

Hello weslyarfan,

What is the value of count going into the loop?
What shell are you using?
If you add this line into your code, it might show you more detail about what is going wrong:-

set -x

With ksh as my shell, the syntax count=$[$count+1] doesn't give a numeric output, and so the while loop fails with a syntax error. It works fine in bash though.

Robin

I am really new in linux att all. So actually I dont know ho to answer your question.

I run it with terminal in Ubuntu and the error result is like I have shown before.
So, How is the manner to run that code in Ubuntu terminal?

Okay, no problem. What output do you get from printf $SHELL ?

I expect it will say bash but it's best to check.

You could probably get away with running this for any shell:-

$SHELL -x your_script

You should see a more explicit running of you code including many of the values being set or tested. It could be quite large, but the last block of lines before the failure will be where the interesting bit will be. Is the overall script quite large or can you post it (in CODE tags)

Robin

Probably just missing count=0 before the posted code.

The $[ ] syntax is rather obsolete these days. If your shell supports it, the more modern COUNT=$((COUNT+1)) is recommended.

I have tried to print $SHELL in my terminal and the result is

/bin/bash

what should i try to run the code shown in upstair?

---------- Post updated at 08:30 PM ---------- Previous update was at 08:21 PM ----------

Thank You Corona688. Your suggest is worked.