0

I was testing a shell script in which arrays were used. This is an example taken from tutorialspoint

#!/bin/sh

NAME[0]="Zara"
NAME[1]="Qadir"
NAME[2]="Mahnaz"
NAME[3]="Ayan"
NAME[4]="Daisy"
echo "First Index: ${NAME[0]}"
echo "Second Index: ${NAME[1]}"

But I am getting this error
test.sh: 3: test.sh: NAME[0]=Zara: not found
test.sh: 4: test.sh: NAME[1]=Qadir: not found
test.sh: 5: test.sh: NAME[2]=Mahnaz: not found
test.sh: 6: test.sh: NAME[3]=Ayan: not found
test.sh: 7: test.sh: NAME[4]=Daisy: not found
test.sh: 8: test.sh: Bad substitution

The link to the exact page is here

0

2 Answers 2

4

The shebang is wrong, this only works in specific shells, e.g. bash.

Sign up to request clarification or add additional context in comments.

1 Comment

It's working when i execute the code as > bash test.sh
1

Simple. You just need to run as -

bash script_name.sh

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.