Datasheet
44
Phase 1
Working on the Command Line
To learn what environment variables are set in your particular session, type env. This command
officially runs a program in a modified environment; however, when typed alone, it displays the
values of all the currently set environment variables. The output of this command is likely to be
quite long, so you may want to pipe it through less or redirect the output to a file for later exam-
ination. Some of the environment variables will have fairly suggestive names, but others are likely
to be obscure. You can find the purpose of some in the man page for bash, but others have meaning
only to particular programs. If you don’t understand the purpose of an environment variable, don’t
try to change it; ignore it or, if you’re curious, try looking it up using a Web search engine.
Criteria for Completion
To complete this task, you should have successfully tested modifications to at least two envi-
ronment variables: $PS1 (to set the shell prompt) and $EDITOR (to set the default editor). You
should have made both transient changes (by setting the variable and using the export com-
mand on a command line) and more permanent changes (by editing a bash configuration file).
Task 1.9: Write Basic Scripts
The bash and other Linux command-prompt shells are more than simple command-line tools;
they’re powerful programming languages. You can string together commands to have them
execute one after another, add variables to improve flexibility, and use program control state-
ments to have parts of the program execute repeatedly or only upon certain conditions.
Programs written in the bash shell language are often referred to as scripts. Compared to
programs written in languages such as C, C++, and Pascal, bash scripts are easy to create but
slow to execute. This makes them good choices for simple programs and for “throwaway”
programs that aren’t likely to be used very often. In fact, many of Linux’s key startup and sys-
tem configuration files are actually shell scripts. Thus, understanding how to create and mod-
ify scripts will help you administer a Linux system.
Scenario
You find that you want to simplify or otherwise improve various tasks that you routinely per-
form, so you want to create scripts to handle these tasks. Specifically, you want a script to
launch a few X programs with one command, a way to simplify account creation tasks, a
script that reports nothing but the computer’s IP address, a script that plays all the .wav audio
files in a directory, and a script that copies files only if the destination file doesn’t already exist.
Scope of Task
Script-writing is a very open-ended activity; scripts can perform a wide variety of tasks, and
there may be multiple ways of achieving the same goals within a script. This particular task
presents a few scripts that illustrate important scripting features.
83484.book Page 44 Monday, September 18, 2006 8:58 AM










