Ravi
Ravi

Reputation: 683

syntax error near unexpected token `((' in Sun Solaris Unix

I have the following logic in the script Setup.sh.

#!/bin/bash

for ((i = 0 ; i < 5 ; i++))
do
  echo "Welcome $i times."
done

When I run the script using the command ./Setup.sh, I get the error

./Setup.sh: line 3: syntax error near unexpected token `(('
./Setup.sh: line 3: `for ((i = 0 ; i < 5 ; i++))'

When I run the script using the command sh Setup.sh , I get the error

Setup.sh: syntax error at line 3: `(' unexpected

When I run the script logic in Execute BASH Shell Script Online using http://www.compileonline.com/execute_bash_online.php, it executes perfectly and prints the following.

Welcome 0 times.
Welcome 1 times.
Welcome 2 times.
Welcome 3 times.
Welcome 4 times.

Can someone help me understand why I get this error on Sun Solaris Unix machine?

Upvotes: 0

Views: 2729

Answers (2)

Jens
Jens

Reputation: 72639

When you run sh Setup.sh the Solaris /bin/sh is used to execute the script. The Solaris /bin/sh is not a POSIX shell and also does not understand the non-portable (()) syntax.

If you use #!/bin/bash it should work. If it doesn't, maybe your bash is very ancient. What does bash --version output?

The online demo uses bash 4.1.2(1)-release.

Upvotes: 3

SzG
SzG

Reputation: 12619

Please check which version of bash you have on the Solaris system.

bash --version

As far as I remember, the (( )) arithmetic notation was introduced recently. And it's a bashism, so it does not work with sh.

The website probably uses a new version of bash.

Upvotes: 1

Related Questions