Datasheet
Task 1.8: Manage the Shell Environment
39
Setup
To prepare for the task, log into your user account on your Linux system. (You can—and
should—perform this task as an ordinary user.) You may perform this task in either a text-
mode or a GUI login, but in the latter case, you must launch an xterm or similar command
prompt window.
Caveats
Performing this task as root poses the usual risks of accidentally damaging the installation. If
you badly corrupt your own bash configuration files, it’s conceivable (but unlikely) that you’ll
be unable to log in again. If this happens, use a root login to copy /etc/skel/.bashrc to your
user home directory and change the ownership of the copied file to your normal user account.
Procedure
To complete this task, you’ll change two environment variables. First you’ll do this tempo-
rarily so that your changes affect just a single login session. You’ll then make your changes
permanent by editing a user configuration file. At the end of this procedure, I describe several
other important environment variables, which you might choose to change if you so desire.
Adjusting Your Shell Prompt
The prompt in bash is controlled through the $PS1 variable. You set a variable by specifying the
variable name (minus the leading dollar sign, $), an equal sign (=), and the value to which you
want to set the variable. In most cases, you should surround the value of the prompt by quotes
("). For instance, you can set your bash prompt to read Your command? by typing the following:
$ PS1="Your command? "
Pay attention to the spaces (and lack thereof), particularly around the equal sign; adding
spaces around the equal sign will cause this command to fail. If you want a space between
the prompt and the point at which you begin typing, be sure to include one at the end of the
new prompt string.
The scenario presented earlier, though, specified that you want to include the time and date
in the command prompt. To do this, you must include special strings that serve as stand-ins
for other data. Specifically, the current date can be denoted by \d and the time can be denoted
by \@. Thus, you can set your prompt to include the date and time by issuing the following
command:
$ PS1="\d \@ $ "
The result might resemble the following, although of course the date and time shown in the
prompt will change with the real date and time:
Thu Jun 08 11:44 AM $
83484.book Page 39 Monday, September 18, 2006 8:58 AM










