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

Compound Variables

The Korn shell also supports compound variables, which are similar to structures or records in other languages, that is a meta-datatype which is a group of related values, each of which can have a different data type. The syntax for declaring compund variables is:

					compound_variable=(
					[datatype]
					field1[=value]
					. . .
					[datatype]
					fieldn[=value]
					)
				

For example, we can use a compound variable to manage employee information:

					$ employee=(
					typeset name=Allenby
					integer id=1243
					float salary=9000.50
					)
				

The syntax to display the value of a compound variable field is:

					${compound_variable.field}
				

Here we access the employee compound variable:

					$ print $employee
					( typeset -E salary=9000.5 name=Allenby typeset -i
					id=1243 )
					$ print ${employee.name} ...

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