Computing.Net > Forums > Unix > sample shell script using arrays

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

sample shell script using arrays

Reply to Message Icon

Name: John Beards
Date: September 9, 2002 at 11:31:35 Pacific
OS: Red Hat 7.x
CPU/Ram: PIII / 128 MB
Comment:

Can someone please provide sample code that utilizes arrays. Or please direct me to a web site that provides good explanations onhow to implement arrays in shell scripts.

Thanks,

J.



Sponsored Link
Ads by Google

Response Number 1
Name: Jerry Lemieux
Date: September 9, 2002 at 17:10:39 Pacific
Reply:

Example:

Name[1]="Fred"
Name[2]="Joe"
print ${Name[*]}

The first 2 commands assign Fred and Joe to slots 1 and 2 in the array (I could have used 0, but that confuses new people). The third command will output:

Fred Joe

Counting the array members is done by:

print ${#Name[*]}

Print the first member of the array:

print ${Name[1]}

Print the second member of the array:

print ${Name[2]}

And there you have all you need to know to create your very own array.

Jerry


0
Reply to Message Icon

Related Posts

See More


ls help Network Unix installation



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: sample shell script using arrays

loops in shell scripts!!! www.computing.net/answers/unix/loops-in-shell-scripts/5140.html

Executing Shell scripts? www.computing.net/answers/unix/executing-shell-scripts/1304.html

Traping Ctrl-Z in KSH Shell script www.computing.net/answers/unix/traping-ctrlz-in-ksh-shell-script/5241.html