- Variables
- Valid Characters
- Scalar
- Array
- Read-Only
- Unsetting
- What's Next
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 it?
This is addressed next through the use of the unset command.