O'Reilly logo

The Linux Command Line by William E. Shotts Jr.

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

Assigning Values to an Array

Values may be assigned in one of two ways. Single values may be assigned using the following syntax:

name[subscript]=value

where name is the name of the array and subscript is an integer (or arithmetic expression) greater than or equal to 0. Note that the first element of an array is subscript 0, not 1. value is a string or integer assigned to the array element.

Multiple values may be assigned using the following syntax:

name=(value1 value2 ...)

where name is the name of the array and value1 value2 ... are values assigned sequentially to elements of the array, starting with element 0. For example, if we wanted to assign abbreviated days of the week to the array days, we could do this:

[me@linuxbox ˜]$ days=(Sun Mon Tue Wed ...

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