Java Reference
In-Depth Information
Entire topics can be—and have been—written on shell programming.
(It's one of our favorite subjects to teach.) Programs written in the shell lan-
guage are often called shell scripts . Such scripts can be powerful yet easy to write
(once you are familiar with the syntax) and can make you very productive in
dealing with all those little housekeeping tasks that accompany program
development. All you need to do (dangerous words, no?) is to put commands
in a text file and give the file execute permissions. But that's a subject for
another day.
Some elements of shell scripting, however, are useful even if you never
create a single shell script. Of these, perhaps the most important to know
(especially for Java programmers) is how to deal with shell variables.
NOTE
We'll be describing the syntax for bash , the default shell on most Linux
distributions. The syntax will differ for other shells, but the concepts are largely
the same.
Any string of alphanumeric or underscore characters can be used as the
name of a variable. By convention shell variables typically use uppercase
names—but that is only convention (although it will hold true for most if
not all of our examples, too). Since commands in Linux are almost always
lowercase, the use of uppercase for shell variables helps them to stand out.
Set the value of a shell variable with the familiar method—the equal sign:
$ FILE=/tmp/abc.out
$
This has assigned the variable FILE the value /tmp/abc.out . But to make
use of the value that is now in FILE , the shell uses syntax that might not be
familiar to you: The name must be preceded with a “ $ ”.
Shell variables can be passed on to other environments if they are exported ,
but they can never be passed back up. To set a shell variable for use by your
current shell and every subsequent subshell, export the variable:
$ export FILE
$
Search WWH ::




Custom Search