Unset / delete a variable

Unsetting or deleting a variable directs the shell to remove the variable from the list of variables that it tracks. Once you unset a variable, you cannot access the stored value in the variable.

 

Following is the syntax to unset a defined variable using the unset command:

 

unset variable_name

 

The above command unsets the value of a defined variable.

 

 

Invoke:

sh unset.sh

 

Output:

My favoutire motorbike is a Ducati Desmosedici
The bike variable has now been unset and will not display here:

 

You cannot use the unset command to unset variables that are marked readonly.