Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

  • Print
  • + Share This

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.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.