Unix Shell - How to handle shell array

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > August 2007 > How to handle shell array





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to handle shell array
moonhk

2007-08-24, 7:23 am

Hi All

how to handle shell array

#!/bin/ksh
p[1]="hk"
p[2]="moon"
echo ${p[1]}
echo ${p[2]}

for i in ${p}
do
echo i=$i
done

Output
=====
hk
moon

Shoud be
========
hk
moon
i=hk
i=moon

Kenan Kalajdzic

2007-08-24, 7:23 am

moonhk <moon_ils-se@yahoo.com.hk> wrote:
> Hi All
>
> how to handle shell array
>
> #!/bin/ksh
> p[1]="hk"
> p[2]="moon"
> echo ${p[1]}
> echo ${p[2]}
>
> for i in ${p}


Since p is an array, you should use ${p[@]} instead of ${p}.

> do
> echo i=$i
> done
>
> [...]


--
Kenan Kalajdzic
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com