The readonly Command

The readonly command sets the value and/or readonly attribute of variables. It is equivalent to the typeset –r command, except that when used within a function, a local variable is not created. This command sets X to readonly and assigns it a value of 1:

					$ readonly X=1
				

This is equivalent to:

					$ typeset —r X=1
				

Multiple variables can be given to the readonly command.

					$ readonly X Y=1 Z=2
				

If no arguments are given, a list of readonly variables and their values is displayed:

					$ readonly
					Z=1
					Y=1
					Z=2
					PPID=175
				

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.