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 How to find files on Linux There are many options you can use to find files on Linux, including searching by file name (or partial name), age, owner, group, size, type and inode number. By Sandra Henry Stocker Jun 24, 2024 8 mins Linux opinion Linux in your car: Red Hat’s milestone collaboration with exida With contributions from Red Hat and critical collaborators, the safety and security of automotive vehicles has reached a new level of reliability. By Sandra Henry Stocker Jun 17, 2024 5 mins Linux how-to How to print from the Linux command line: double-sided, landscape and more There's a lot more to printing from the Linux command line than the lp command. Check out some of the many available options. By Sandra Henry Stocker Jun 11, 2024 6 mins Linux how-to Converting between uppercase and lowercase on the Linux command line Converting text between uppercase and lowercase can be very tedious, especially when you want to avoid inadvertent misspellings. Fortunately, Linux provides a handful of commands that can make the job very easy. By Sandra Henry Stocker Jun 07, 2024 5 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe