For the purpose of an experiment...
Suppose I did this
bash="unset DISPLAY; export DISPLAY"
so I can make
DISPLAY undefined. How can I restore the original value set? Or at least know what it was?
In general you write it down before hand.
If you're asking about this in theory, then you simply store the old value somewhere else before modifying it, then put it back whenever you want.
If you're asking about this because now you're screwed and are hoping that there's something that will bail you out, then I have bad news for you...
I'm not sure there's an easy way to do this (like
What is the context of doing this .. do you want this to be available automatically? I am not aware of this as a feature of any shell.
One obvious solution would be to explicitly save the variable before you change it, and then later restore it. Using the VENDOR environment variable as an example:
Save the original value:
Assign a new value:
Restore the original value:
You can't, there's no undo. Save the value in another variable (or in a file or wherever you like) if you want to have it available later.
If you want to run a single command without the environment variable, use
You can also use the syntax
You can't unset a variable this way, but you can set it to an empty value, which is often good enough.
You can also keep changes local to a subshell. Parentheses delimit commands to perform in a subshell.
You can run a separate shell with a different environment. Type