Read-Only

The shell provides a way of making a variable read-only. After a variable is declared as read-only, its value cannot be changed. This is shown in the following example:

$ Children=Meshia
$ readonly Children   # Sets the readonly attribute
                      # on the Children variable
$ echo $Children
Meshia
$ Children=David
ksh: Children: is read only

You cannot have any more children because when an attempt to change its value occurred, the shell produced an error and would not allow the value associated with Children to change.

This brings up an interesting problem. If a value is set, such as when you assigned multiple children to the varname Children, how can it be changed? Better yet, when a variable has been set to readonly, how do you get rid of ...

Get Korn Shell Programming by Example 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.