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:
The above command unsets the value of a defined variable.
#!/bin/bash bike="Ducati Desmosedici" echo "My favoutire motorbike is a $bike" unset bike echo "The bike variable has now been unset and will not display here: $bike"
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.