Set a local and environment variable using Bash on Linux
Check for a local or environment variables for a variable called LOL in Bash:
$ set | grep LOL
$
$ env | grep LOL
$
Sanity check, no local or environment variable called LOL.
Set a local variable called LOL in local, but not environment. So set it:
$ LOL="so wow much code"
$ set | grep LOL
LOL='so wow much code'
$ env | grep LOL
$
Variable 'LOL' exists in local variables, but not environment variables. LOL will disappear if you restart the terminal, logout/login or run exec bash.
Set a local variable, and then clear out all local variables in Bash
$ LOL="so wow much code"
$ set | grep LOL
LOL='so wow much code'
$ exec bash
$ set | grep LOL
$
You could also just unset the one variable:
$ LOL="so wow much code"
$ set | grep LOL
LOL='so wow much code'
$ unset LOL
$ set | grep LOL
$
Local variable LOL is gone.
Promote a local variable to an environment variable:
$ DOGE="such variable"
$ export DOGE
$ set | grep DOGE
DOGE='such variable'
$ env | grep DOGE
DOGE=such variable
Note that exporting makes it show up as both a local variable and an environment variable.
Exported variable DOGE above survives a Bash reset:
$ exec bash
$ env | grep DOGE
DOGE=such variable
$ set | grep DOGE
DOGE='such variable'
Unset all environment variables:
You have to pull out a can of Chuck Norris to reset all environment variables without a logout/login:
$ export CAN="chuck norris"
$ env | grep CAN
CAN=chuck norris
$ set | grep CAN
CAN='chuck norris'
$ env -i bash
$ set | grep CAN
$ env | grep CAN
You created an environment variable, and then reset the terminal to get rid of them.
Or you could set and unset an environment variable manually like this:
$ export FOO="bar"
$ env | grep FOO
FOO=bar
$ unset FOO
$ env | grep FOO
$