TABLE 2-7
(continued)
Variable
Description
PWD
This is the directory that is assigned as your current directory. This value changes each
time you change directories using the cd command.
RANDOM
Accessing this variable causes a random number to be generated. The number is
between 0 and 99999.
SECONDS
The number of seconds since the time the shell was started.
SHLVL
The number of shell levels associated with the current shell session. When you log in
to the shell, the SHLVL is 1. Each time you start a new bash command (by, for
example, using su to become a new user, or by simply typing bash), this number is
incremented.
TMOUT
Can be set to a number representing the number of seconds the shell can be idle
without receiving input. After the number of seconds is reached, the shell exits. This is
a security feature that makes it less likely for unattended shells to be accessed by
unauthorized people. (This must be set in the login shell for it to actually cause the
shell to log out the user.)
UID
The user ID number assigned to your username. The user ID number is stored in the
/etc/password
file.
Setting Your Own Environment Variables
Environment variables can provide a handy way to store bits of information that you use often
from the shell. You can create any variables that you want (avoiding those that are already in use)
so that you can read in the values of those variables as you use the shell. (The
bash
man page lists
variables already in use.)
To set an environment variable temporarily, you can simply type a variable name and assign it to a
value. Here's an example:
$ AB=/usr/dog/contagious/ringbearer/grind ; export AB
This example causes a long directory path to be assigned to the
AB
variable. The
export AB
com-
mand says to export the value to the shell so that it can be propagated to other shells you may
open. With
AB
set, you go to the directory by typing the following:
$ cd $AB
The problem with setting environment variables in this way is that as soon as you exit the shell in
which you set the variable, the setting is lost. To set variables permanently, add variable settings to
a bash configuration file, as described later in this section.
Another option to add the settings to the bash configuration file is to create an exe-
cutable script file that contains these settings. This is useful when you don't use the set-
tings all the time, but need to use them occasionally. They are there only for the life of the session
after the script file has run.
NOTE
NOTE
62
Linux First Steps
Part I