Datasheet
40
Phase 1
Working on the Command Line
In most distributions, the system is configured with default prompts that include your user-
name, the computer’s hostname, and the current directory, but details differ. You can learn
what your shell prompt is by typing echo $PS1. This command displays the contents of the
$PS1 variable. Consult the man page for bash for more information on common substitution
strings, including those found in your distribution’s default shell prompt.
Setting the $PS1 variable as just described has one important limitation: The change is
restricted to the current running instance of bash. Any program launched from bash will
inherit the default value of $PS1. This is true even of bash itself. With your altered prompt dis-
played, try typing bash to launch another shell from the current one. Your command prompt
will be replaced by your default prompt. Typing exit from the new shell will return you to the
original one with the modified prompt.
To make a change that can be inherited by programs launched from your current session,
you must use the export command after setting the variable:
$ PS1="\d \@ $ "
$ export $PS1
A variable that’s been exported in this way is referred to as an environment variable, as
opposed to a simple variable. Alternatively, you can combine these commands on a single line:
$ export PS1="\d \@ $ "
After typing these commands, if you launch a new instance of bash, it will inherit the
changed command prompt. Even this change, though, won’t affect new logins or new xterm
windows; to make your change truly permanent, you must adjust configuration files, as
described shortly in “Making Your Changes Permanent.”
Setting a Program-Specific Environment Variable
Many environment variables affect non-bash programs. One of these that you might want to
adjust is $EDITOR. Some Linux programs launch an external text editor for certain operations,
and these programs often consult the $EDITOR environment variable to determine what pro-
gram to use. First, check what program your account is configured to use by default:
$ echo $EDITOR
/usr/bin/vi
Although the $EDITOR variable is frequently defined, it isn’t guaranteed to be.
If a variable isn’t set, displaying it with echo will show an empty line as output.
Of course, your system might not be configured to use Vi, as shown in this example.
Another test is to use a utility that consults the $EDITOR environment variable. One such tool
is crontab; type crontab -e and you should see a (probably empty) file appear in your
default editor. Exit from this editor without making any changes to the file.
83484.book Page 40 Monday, September 18, 2006 8:58 AM










