Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
Shells: User's Guide: HP 9000 Computers > Chapter 21 Basic Shell Programming

Accessing Arrays

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Index

Arrays are a collection of contiguous elements that can be accessed by a subscript. Declaration of arrays in POSIX and Korn Shell is very similar to that of the C Shell. An array's syntax is:

array [subscript]=value

The first line sets the element of the named array at the designated subscript to the value. Unlike C Shell, POSIX and Korn Shell start placement of values at the 0 element.

In this example:

$ testa[0]=first
$ testa[1]=second
$ echo ${testa[1]}
second
$ echo ${testa[*]}
first second

the array testa first two elements (0 and 1) are set to first and second. The following echos, display the value of the 1 element and then the value of every array element as designated by the *.

See “Parameter Substitution Conventions” for other possible array subscripts and uses for arrays.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-1991 Hewlett-Packard Development Company, L.P.