1

Hello I'm testing my self by using a tutorial on writing linux shell scripts ran into this issue usinng shell arrays. the syntax is being written using vi

name[0]=chuck
name[1]=samson

echo "hello, ${name[0]}" echo "hello, ${name[1]}"

and saved file using :wq. I tried to run the file using sh svar.sh but got

name[0]=chuck is not found
name[1]=samson is not found

However when using coding ground GNU Bash v4.4 the scripts run correctly Why it doesn't work under this on this OS?

Kulfy
  • 17,696

1 Answers1

3

Add #!/bin/bash shebang.

Older Ubuntu versions had ash as the default shell, that didn't support arrays.

And run the script this way:

./svar.sh

Don't use sh, etc.

Pilot6
  • 90,100
  • 91
  • 213
  • 324