I’m doing a task, but I got an error: scr.sh: 3: Syntax error: word unexpected (expecting ")"). When I try to run my schell script on my local computer server, it works, but on the helios ssh server it return an error. Here’s my test code:
#!/bin/bash
arr=(kitten dog parrot)
for i in ${arr[@]}
do
echo $i
done
I tried to declare array like this:
arr=("kitten" "dog" "parrot"), it was the same error.
Using declare -a arr didn’t work
I run it like this:
sh scr.sh
>Solution :
The problem is how you run the script. You tell it to use sh instead of bash. Instead do
bash scr.sh
or make the file executable
chmod +x scr.sh
and then you can run it without manually specifying the scripting language every time:
./scr.sh