Shell - Doesn't support array

By xngo on April 7, 2020

I was running my shell script and it gave me the following error message:

Syntax error: "(" unexpected


It is my fault. I ran a Bash script with sh. sh doesn't support array, that is why it threw a syntax error message. For example, I have the following script.

animals=(cat dog fish)
echo ${animals[@]}

If I run it as


I get the error, but if I run it as


It is working fine.

About the author

Xuan Ngo is the founder of He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.