Java Reference
In-Depth Information
You can combine the assignment of a value with the exporting into one
step. Since repeating the export doesn't hurt, you will often see shell scripts use
the export command every time they do an assignment, as if it were part of
the assignment syntax—but you know better.
$ export FILE="/tmp/way.out"
$
NOTE
The shell uses the dollar sign to distinguish between the variable name and just
text of the same letters. Consider the following example:
$ echo first > FILE
$ echo second > TEXT
$ FILE=TEXT
$ cat FILE
first
$
The cat command will dump the contents of the file named FILE to the
screen—and you should see first . But how would you tell the shell that you
want to see the contents of the file whose name you have put in the shell
variable FILE ? For that you need the “ $ ”:
$ cat $FILE
second
$
This is a contrived example, but the point is that shell syntax supports ar-
bitrary strings of characters in the command line—some of them are filenames,
others are just characters that you want to pass to a program. It needs a way
to distinguish those from shell variables. It doesn't have that problem on the
assignment because the “ = ” provides the needed clue. To say it in computer
science terms, the “ $ ” syntax provides the R-value of the variable. (Not the
insulation R-value, but what you expect when a variable is used on the Right-
hand-side of an assignment operator, as opposed to the L-value used on the
Left-hand-side of an assignment operator.)
There are several shell variables that are already exported because they are
used by the shell and other programs. You may need or want to set them to
customize your environment. Since they are already exported, you won't need
to use the export command and can just assign a value, but it doesn't hurt.
Search WWH ::




Custom Search