November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

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

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>