Search code examples
linuxbashshellfor-loopdash-shell

syntax of for loop in linux shell scripting


I have a problem implementing a for loop. I get this error when I execute my script

test1.sh: 2: Syntax error: Bad for loop variable

I don't understand this error.

This is my script

#!/bin/bash
for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times..."
done

can any one tell me syntax for for loop in sh(in ubuntu it links to dash shell) shell in ubuntu?


Solution

  • You probably run it with sh, not bash. Try bash test1.sh, or ./test1.sh if it's executable, but not sh test1.sh.