creating array variable

Hi all,

i am quite fimiliar with shell scripting but i wouldn't regard myself as a semi professional at it.

I am trying to create an array variable to read in 4 lines from a file using head and tail command in a pipeline and store each line into each array. I have done the scripting in unix but for some reason i keep getting syntax errors during runtime saying 'mon=' unexpected.

for the moment i am trying to create a simple script to store months Jan, Feb Mar Apr into array mon but its not having it and i don't know why. i did google searches and i tried a number of the examples i found but none work
i tried to use declare -a mon but it says "declare: not found" - is it something to do with the first line - #!/bin/bash?
#!/bin/bash

mon=( Jan Feb Mar Apr )

echo $mon

can someone please throw some light onto this becuase its doing my head in.

thanks in advance

Mani

Hi all,

i am quite fimiliar with shell scripting but i wouldn't regard myself as a semi professional at it.

I am trying to create an array variable to read in 4 lines from a file using head and tail command in a pipeline and store each line into each array. I have done the scripting in unix but for some reason i keep getting syntax errors during runtime saying 'mon=' unexpected.

for the moment i am trying to create a simple script to store months Jan, Feb Mar Apr into array mon but its not having it and i don't know why. i did google searches and i tried a number of the examples i found but none work
i tried to use declare -a mon but it says "declare: not found" - is it something to do with the first line - #!/bin/bash?
#!/bin/bash

mon=( Jan Feb Mar Apr )

echo $mon

can someone please throw some light onto this becuase its doing my head in.

thanks in advance

Mani

The syntax isn't the same between bash and ksh :

#!/usr/bin/bash

declare -a mon
mon=( Jan Feb Mar Apr )

echo ${#mon[*]}
echo ${mon[2]}
#!/usr/bin/ksh

set -A mon -- Jan Feb Mar Apr

echo ${#mon[*]}
echo ${mon[2]}