Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 46783  / 2 Years ago, fri, october 21, 2022, 12:59:35

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.


More From » scripts

 Answers
6

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.


[#27642] Friday, October 21, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ippalogu

Total Points: 215
Total Questions: 127
Total Answers: 146

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
;