I was running my shell script and it gave me the following error message:
Syntax error: "(" unexpected
Solution
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.
#!/bin/bash animals=(cat dog fish) echo ${animals[@]}
If I run it as
sh array-test.sh
I get the error, but if I run it as
./array-test.sh
It is working fine.