Array Variables

One-dimensional arrays are supported by the Korn shell. Arrays can have a maximum of 4096 elements. Array subscripts start at 0 and go up to 4096 (or the maximum element minus one). Any variable can become a one-dimensional array by simply referring to it with a subscript. Here, variable X is set to A:

					$ X=A
				

By explicitly assigning X[1] a value, variable X is transformed into an array variable:

					$ X[1]=B
				

The original assignment to variable X is not lost. The first array element (X[0]) is still assigned A.

Table 3.6. More Variable Expansion Formats
${variable//pattern1/pattern2} replace all occurrences of pattern1 with pattern2 in variable
${variable/pattern1/pattern2} replace first occurrence of pattern1 with pattern2 in ...

Get Korn Shell: Unix and Linux Programming Manual, Third Edition, The now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.