May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  

Categories

May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  

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>