Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

scr.sh: 3: Syntax error: word unexpected (expecting ")")

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading