O'Reilly logo

Linux Shells by Example by Ellie Quigley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.8. Arrays

10.8.1. What Is an Array?

In the TC shell, an array is simply a list of words, separated by spaces or tabs, and enclosed in parentheses. The elements of the array are numbered by subscripts starting at one. If there is not an array element for a subscript, the message "Subscript out of range" is displayed. Command substitution will also create an array. If the $# notation precedes an array name, the number of elements in the array is displayed.

Example 10.71.
1  > set fruit = ( apples pears peaches plums )
2  > echo $fruit
						apples pears peaches plums

3  > echo $fruit[1]
						Subscripts start at 1
						apples

4  > echo $fruit[2–4]
						Prints the 2nd, 3rd, and 4th elements
						pears peaches plums

5  > echo $fruit[6]
						Subscript out of range.

6  > echo ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required