April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

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>