Printing arrays are not working in shell script

I am kind of new in shell scripting and trying to learn arrays. I declared array value but when I am trying to print that array it is giving me an error(bad substitution).
I am pasting the code below, please suggest to me what is wrong here-

➜  ~ cat

echo 1
echo "${array[0]}"
➜  ~ sh
1 5: Bad substitution

Thanks in advance.

>Solution :

Depending on the system you’re using sh might be not be Bash and
it’s not Bash on yours, it can be dash for example. Run your script with Bash:

$ bash

Or set an executable bit and call the script without providing the name of the interpreter since you already have the shebang:

$ chmod +x
$ ./

Leave a Reply