unexport/remove a variable in the shell


say you have assigned some value to a variable from the shell or a shell script using the export command and now you want to remove that variable, either programatically or manually.

# export var="hello world!"
# echo ${var}
hello world!

#

you may remove this variable from the shell with the unset command. syntax and example below

unset <variable name>

# echo ${var}
hello world!
# unset var
# echo ${var}

#

It’s gone!

Another way would be to use the export -n command. Check the man page for export on your distro. It’s not supported on some versions of export.

Leave a Reply

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