Environment variables help to configure your account so that it’s easier to use, but they can also be changed to suit your needs and preferences. Credit: Jan Smith Simply put, environment variables are variables that are set up in your shell when you log in. They are called “environment variables” because most of them affect the way your Unix shell works for you. One points to your home directory and another to your history file. One identifies your mail file, while another controls the colors that you see when you ask for a file listing. Still another sets up your default search path. If you haven’t examined your environment variables in a while, you might be surprised by how many of them are configured. An easy way to see how many have been established in your account is to run this command: $ env | wc -l 25 The env command (or printenv) will list all of the enviroment variables and their values. Here’s a sampling: $ env | sort | head -10 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus HISTCONTROL=ignorespace HISTFILE=/home/shs/.history HISTIGNORE=history:pwd:man *:ls:ls * HISTSIZE=100 HISTTIMEFORMAT=%h %d %H:%M:%S> HOME=/home/shs LANG=en_US.UTF-8 LESSCLOSE=/usr/bin/lesspipe %s %s LESSOPEN=| /usr/bin/lesspipe %s In this sampling of settings, we see a signalling setting, settings that control how many previous commands are displayed when you use the history commands, what commands are ignored, and how history information is formatted. We also see some locale data, as well as settings for the less command. You can display a single variable with a simple echo command. $ echo $HISTFILE /home/shs/.history You can create a variable on the command line by using a command like “myvar=11”, but it’s not really an environment variable unless you also export it and it won’t be available in subshells. If, instead, you typed “export myvar=11”, the variable will then also be available if you initiate a subshell. Environment variables will be remembered only if you make them permanent (as far as “permanent” goes on a Unix system) by adding them to one of your startup files — like .~/bashrc, ~.profile or ~/.login. You can get rid of environment variables fairly easily with the unset command, but remember to remove them from the file in which they were set up initially. If you remove a variable that you need, you might have some interesting consequences. $ unset HOME $ cd /tmp $ cd -bash: cd: HOME not set Fortunately, reversing the change is just as easy. $ export HOME=/home/shs $ cd $ pwd /home/shs Some environment variables are set up in system files like /etc/profile that are read before your local setup files when you log in. Environment variables can be changed or unset, but they can also be augmented. If your search path is set up in /etc/profile, you can redefine it in your local .profile or add to it with a command like this: PATH=~/bin:$PATH:/apps/bin In this case, your personal bin directory (~/bin) would then be searched before other directories on your path and /apps/bin would be searched last provided it isn’t also included in the initial $PATH. Environment variables help to configure your account so that it’s easier to use, but they can also be changed to suit your needs and preferences. Related content how-to Compressing files using the zip command on Linux The zip command lets you compress files to preserve them or back them up, and you can require a password to extract the contents of a zip file. By Sandra Henry-Stocker May 13, 2024 4 mins Linux opinion NSA, FBI warn of email spoofing threat Email spoofing is acknowledged by experts as a very credible threat. By Sandra Henry-Stocker May 13, 2024 3 mins Linux how-to The logic of && and || on Linux These AND and OR equivalents can be used in scripts to determine next actions. By Sandra Henry-Stocker May 02, 2024 4 mins Linux how-to Using the apropos command on Linux By Sandra Henry-Stocker Apr 24, 2024 3 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe