O'Reilly logo

Korn Shell: Unix and Linux Programming Manual, Third Edition, The by Anatole Olczak

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

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 ...

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