user1033152
user1033152

Reputation: 11

Array bash script doesn't work

#!/bin/bash
ARRAYNAME=( 'time1' 'life' 'time2' )
echo ${ARRAYNAME[1]}

In the above code when i run my script as

$ sh ex1.sh

it gives an error message:

ex1.sh: 2: Syntax error: "(" unexpected

Why is this?

Upvotes: 1

Views: 346

Answers (2)

PsyberMonkey
PsyberMonkey

Reputation: 1

Your "shebang" lines uses bash shell ("/bin/bash") but you're probably invoking another shell ("sh") invoking another shell to execute your script. Try this :

$ chmod 700 ex1.sh

This will make your script executable. Then run it :

$ ./ex1.sh

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798516

sh on your system is not bash.

Upvotes: 5

Related Questions