Shell script arrays Syntax error: “(” unexpected

Recently when I am using arrays in a script I got the error message as “Shell script arrays Syntax error: “(” unexpected”.

$ sh arrays.sh  #In arrays.sh script I defined some arrays trying to extract values form it

The out put I got after running the script is below

Shell script arrays Syntax error: “(” unexpected

I am struggled a bit to resolve this issue, and the solution I got to know is, most probably in your OS the bash version is updated.

So it is unable to resolve the array assignment.

To fix the issue use bash instead of using sh while executing the script, that should not throw any syntax error.

Example: 

Run arrays.sh as

$ bash arrays.sh

-Sany

8 comments on “Shell script arrays Syntax error: “(” unexpected

  1. Pingback: pc.casey.jp » 意外な理由(?)で「Shell script arrays Syntax error: “(” unexpected」

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s