Question Locked

SHELL ARRAY

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi I was going to do something with arrays
so I made a small dummy prg in a shell file

#!/bin/sh
declare -a arr
arr[1]=100
arr[2]=123
echo ${arr[1]}

Now the problem is that if I run this code one by one in the terminal it runs perfectly
but if I use this as a shell file this is the error it gives

arr.sh: 2: declare: not found
arr.sh: 3: arr[1]=100: not found
arr.sh: 4: arr[2]=123: not found
arr.sh: 5: Bad substitution

I cant make out the heads and tails of why this is happening ....
someone plz tell me what the hell is going wrong.....

1 reply

This discussion is closed to new replies.