I want use an array in my shell script test.sh as follows:
#!/bin/bash
index=100345
NAME[0]="Zara"
NAME[$index]="Qadir"
echo "First Index:" ${NAME[0]}
echo "Second Index:" ${NAME[$index]}
but when execute it by sh test.sh:
NAME[0]=Zara: not found
NAME[100345]=Qadir: not found
test.sh: ${NAME[...}: Bad substitution
How to solve it?
bash(bourne again shell) andksh(korn shell) support array. If you are trying to run your script using the legacysh(bourne shell), it will not work as it doesn't support array.echo $SHELLto see what shell you are using.$SHELLshows the login shell, not necessarily the shell you are using.