![]() |
4.3.2 Environment Variables When Linux programs are run they have the open file descriptors described above. They also carry with them a list of “name=value” pairs called their environment. These environment variables allow for context to be shared among several successively executed programs. Some examples of environment variables are: • USER is the name you used to log in. • HOME is the directory where you start when you log in. • PATH is the list of directories searched for executable files. To see the environment variables defined in your current shell, type env at the command prompt: $ env HOME=/home/user01 USER=user01 PATH=/bin:/usr/bin:/usr/local/bin:/home/user01/bin ... $ The names of environment variables, sometimes referred to as shell vari- ables, are traditionally uppercase, though that is only a convention. The variable names are treated in a case sensitive fashion (e.g., Home != HOME). You can set environment variables for use in the current shell with a simple assignment statement: $ VAR=value That will set the value for the duration of this shell, but not for any of its sub- processes. Since running another program is a subprocess, such an assignment won’t be visible in your running program. Instead, you can export the variable so that it is carried forward to all subprocesses:1 $ export VAR=value
|