< Previous | Contents | Next >
Assigning Values To An Array
Values may be assigned in one of two ways. Single values may be assigned using the fol- lowing 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 zero. Note that the first element of an array is subscript zero, not one. 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 value... are values assigned sequentially to ele- ments of the array, starting with element zero. For example, if we wanted to assign abbre- viated days of the week to the array days, we could do this:
[me@linuxbox ~]$ days=(Sun Mon Tue Wed Thu Fri Sat)
[me@linuxbox ~]$ days=(Sun Mon Tue Wed Thu Fri Sat)
It is also possible to assign values to a specific element by specifying a subscript for each value:
[me@linuxbox ~]$ days=([0]=Sun [1]=Mon [2]=Tue [3]=Wed [4]=Thu
[me@linuxbox ~]$ days=([0]=Sun [1]=Mon [2]=Tue [3]=Wed [4]=Thu
Assigning Values To An Array
[5]=Fri [6]=Sat)
[5]=Fri [6]=Sat)