Apple Xserve Up Mac OS X Server Specifications Page 24

  • Download
  • Add to my manuals
  • Print
  • Page
    / 329
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 23
24 Chapter 1 Executing Commands
Using Environment Variables
Some commands require the use of environment variables for their execution.
Environment variables are inherited by all commands executed in the shell’s context.
The shell uses environment variables to store information, such as the name of the
current user, the name of the host computer, and the paths to any commands.
You can create environment variables and use them to control the behavior of your
command without modifying the command itself. For example, you can use an
environment variable to have your command print debug information to the console.
To set the value of an environment variable, use the appropriate shell command to
associate a variable name with a value. For example, to set the variable PATH to the
value
/bin:/sbin:/user/bin:/user/sbin:/system/Library/, you would enter the
following command in a Terminal window:
$ PATH=/bin:/sbin:/user/bin:/user/sbin:/system/Library/ export
PATH
This modifies the environment variable PATH with the value assigned.
To view all environment variables, enter the following:
$ env
When you launch an application from a shell, the application inherits much of the
shell’s environment, including exported environment variables. This form of inheritance
can be a useful way to configure the application dynamically. For example, your
application can verify for the presence (or value) of an environment variable and
change its behavior accordingly.
Different shells support different semantics for exporting environment variables, so see
the man page for your preferred shell for further information.
Although child processes of a shell inherit the environment of that shell, shells are
separate execution contexts that do not share environment information with one
another. Thus, variables you set in one Terminal window are not set in other Terminal
windows.
After you close a Terminal window, variables you set in that window are gone. If you
want the value of a variable to persist between sessions and in all Terminal windows,
you must set it in a shell startup script.
Another way to set environment variables in Mac OS X is with a special property list in
your home folder. At login, the computer looks for the ~/.MacOSX/environment.plist
file. If the file is present, the computer registers the environment variables in the
property list file.
Page view 23
1 2 ... 19 20 21 22 23 24 25 26 27 28 29 ... 328 329

Comments to this Manuals

No comments