Is it possible to export
a variable in Bash, then later un-export it, without unsetting it entirely? I.e. have it still available to the current shell, but not to sub-processes.
You can always do this, but it's ugly (and I'm curious):
export FOO #... _FOO=$FOO unset FOO FOO=$_FOO
Answers about other shells also accepted.
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. The above example does not print anything. You cannot use the unset command to unset variables that are marked readonly.
export -n FOO
From help export
:
Options:
-f
refer to shell functions-n
remove the export property from each NAME-p
display a list of all exported variables and functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With