Loading...
Shell Script

Unset Variable and Readonly Variable

Unset Variable:

The shell built-in unset command is used for unsetting the data that an initialized variable is holding.

Syntax: unset <Variable Name>

Example: unset name

The above example will unset the data for the variable name is holding.

Readonly Variable:

The shell allows to mark variables as readonly; once the value is marked as readonly it cannot be charged

Syntax: readonly <Variable Name>

Example: readonly name

The above example will set the variable “name” as readonly

$ name = “Ram”
$ readonly name
$ echo $name
Ram
$ unset name
ksh: unset: warning: name: is readonly

Leave a Reply

Your email address will not be published. Required fields are marked *