Environment variables and current context
We mentioned Environment Variables in Chapter 7, where we also explored the basic shell and terminal usage. Environment variables are simple key-value pairs separated by an equal sign. With the env
or printenv
commands, we can see all the variables valid in the current shell session. Here are some from my printenv
output:
PWD=/home/luke HOME=/home/luke LANG=en_US.UTF-8 LANGUAGE= LOGNAME=luke USERNAME=luke MAIL=/var/spool/mail/luke XDG_SESSION_DESKTOP=gnome
We can access these values in the shell with the dollar sign $
like this: $ echo $LOGNAME
. In this case, the shell will replace $LOGNAME
with luke
when printing. Each program or script started in the shell can read them, and some can add new ones. Thus, the Environment Variables are part of the current context in which programs are executed. Remember that Environment Variables are case sensitive, like any terminal command and its parameters.
All the variables we see when we use printenv...