Memo on manipulating Linux environment variables
Reminder: you can left-scroll and right-scroll the long code blocks.
Some common environment variables
- PATH : list of paths to be searched for commands.
- USER : current logged in user.
- HOME : current user’s home directory.
- BASH_VERSION : bash version
- SHELL : current user’s shell path.
- EDITOR : default file editor used when we type
edit
in the terminal. - LOGNAME : name of the current user.
- LANG : current locales settings.
- TERM : current terminal emulation.
- MAIL : current user’s email storing location.
Display environment variable values
1 | # display the USER env var |
Set environment variables for a shell session
1 | # set FOO_VAR and BAR_VAR in the current shell session only |
Set environment variables permanently
You can edit one these files:
~/.bashrc
: per-user environment variables loaded by the bash shell. Usesource ~/.bashrc
to load the new vars in the current shell.1
2export USER_VAR1="foo"
export USER_VAR2="bar"/etc/profile
: environment variables loaded by the bash shell for all users.1
2export SHELL_VAR1="foo"
export SHELL_VAR2="bar"/etc/environment
: system-wide environment variables. ⚠️ In this file, we don’t writeexport
.1
2ENV_VAR1="foo"
ENV_VAR2="bar"
That’s all for this memo. Leave a comment ✍️ and a “Like” ❤️ if you found this post useful 😉
Thanks for reading !
See you soon !
Keep learning !
Written on Tue Dec 13th 2022, 10:02 GMT+00:00.
Last updated on Tue Dec 13th 2022, 10:02 GMT+00:00.