[wellylug] arrays in bash?

Alex Thomson alex.thomson at solnetsolutions.co.nz
Tue May 22 13:39:02 NZST 2007


Try something along the lines of:

declare -a MYARRAY
MYARRAY = ( 'fish' 'yuk' 'chocolate' 'yum' 'icecream' 'yum')

arraynum=${#MYARRAY}

for ((i=0;i<$arraynum;i+=2)); do
   echo I think ${MYARRAY[${i}]} is ${MYARRAY[${i+1}]}
done

Maybe a logic in there somewhere (haven't tried it), but should be 
enough to get you started....

Sigurd Magnusson wrote:
> SilverStripe 
> <http://www.silverstripe.com/home/?utm_source=mailprimer&utm_medium=email> 
>
>
> how do iterate of an array in bash?
>
>
> e.g. can someone change this psuedocode into bash... :)
>
> myarray = ("fish", "yuck"),
> ("chocolate", "yum"),
> ("icecream", "yum")
>
> for food in $myarray; do
> echo I think that $food is $myarray[$food]
> done
>
> Sigurd Magnusson | Operations Director
>
> *SilverStripe*
> http://www.silverstripe.com 
> <http://www.silverstripe.com/home/?utm_source=mailprimer&utm_medium=email> 
>
>
> Phone: 	+64 4 978 7332
> Mobile: 	+64 21 421 208
> Skype: 	
>
> 	Level 3
> 97-99 Courtenay Place
> Wellington, New Zealand
>
> [0800 MAILPRIMER] <http://www.mailprimer.com/>
>
> ------------------------------------------------------------------------
>
>
>   



Attention:
This email may contain information intended for the sole use of
the original recipient. Please respect this when sharing or
disclosing this email's contents with any third party. If you
believe you have received this email in error, please delete it
and notify the sender or postmaster at solnetsolutions.co.nz as
soon as possible. The content of this email does not necessarily
reflect the views of SolNet Solutions Ltd.




More information about the wellylug mailing list