1

When i'm using for like for i in 1 2 3 4 5 then my file contains

#!/bin/sh at the top

But when i'm using for(( i = 0; i<=5; i++)) then it is showing error

Syntax error: Bad for loop variable

and running properly when I remove shebang.

Please tell me the reason behind this.

1 Answer 1

5

You need to run with BASH, so use BASH shebang:

#!/bin/bash

Since this arithmetic BASH loop syntax isn't supported in older bourne shell:

for ((i = 0; i<=5; i++)); do
   echo "$i"
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.