Loop variable error in for loop

for(( i = 0; i<=5; i++)) is Bash specific and doesn't work with plain Bourne shell (/bin/sh).

If you remove the shebang the script is run by your current shell (which likely is Bash) so it works.

Replace #!/bin/sh with #!/bin/bash to make the shebang work.


for(( i = 0; i<=5; i++))

for this type of loop only runs on Bash shell. so, if you want to run this, then try this command :

$bash filename.sh

I think It will work fine. and see this one also.


I have solved this problem by using ./ instead of sh command. For an example if you put sh test.sh instead just make your command as ./test.sh And most probably problem will be solved.