1845956 Members
2497 Online
110250 Solutions
New Discussion

Re: Unix Array Variables

 
ezhilarasan_1
Occasional Advisor

Unix Array Variables

Hi,


I want a simple Unix shell programes to understand unix array variables of character strings and numbers.
(define, setting value, manipulation, and printing).


Thanks
Ezhil
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor

Re: Unix Array Variables

Hi Ezhil:

Perhaps this helps:

#!/usr/bin/sh
echo "Enter a series of space-delimited fields to populate ARY"
read LINE
set -A ARY ${LINE}
echo "${#ARY[*]} elements exist"
echo "element_0 = ${ARY[0]}"
echo "element_1 = ${ARY[1]}"
exit 0

The 'set' declares an array named ARY and populates it with the contents of LINE.

You have knowledge of how many elements exist as shown and how to reference individual elements.

See the manpages for 'sh-posix' for more information, particularly the 'set' statement.

Regards!

...JRF...
Arunvijai_4
Honored Contributor

Re: Unix Array Variables

Hi,

Check these links for more information

http://www.samspublishing.com/articles/article.asp?p=29246&rl=1
http://www.awprofessional.com/articles/article.asp?p=99035&seqNum=4&rl=1

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"