1827807 Members
2396 Online
109969 Solutions
New Discussion

ksh arrays

 
James J. Green
Occasional Contributor

ksh arrays

The man page for ksh says the shell supports simple one-dimensional arrays. I printed the page and tried creating/using arrays. Could not get it to work. Also tired of using cutting (cut) one char at a time in a loop.
So the question is:
What is the correct syntax to get arrays to work? Could you give me an example?

Thanks,
jg
2 REPLIES 2
S.K. Chan
Honored Contributor

Re: ksh arrays

Just a quick example ..

1) Declare your array

# DAYS[0]=Mon DAYS[1]=Tue DAYS[2]=Wed
or
# set -A DAYS Mon Tue Wed

2) The var expansion example

# print $DAYS
Mon
# print $DAYS[0]
Mon
# print $DAYS[1]
Tue
# print ${DAYS[*]}
Mon Tue Wed
# print ${#DAYS[*]}
3
Justo Exposito
Esteemed Contributor

Re: ksh arrays

Hi James,

Example:
to define:
LV[0]=/dev/vg01/lvol1
LV[1]=/dev/vg01/lvol2
LV[2]=/dev/vg01/lvol3
LV[3]=/dev/vg01/lvol4
LV[4]=/dev/vg01/lvol5

to use it:
for I in ${LV[@]}
do
echo ${LV[$I]}
done

Regards,

Justo.
Help is a Beatiful word