Sie sind auf Seite 1von 10

Environment Variables and Local Variables

• Environment Variables are dynamic values which


affect the processes or programs on a computer.
They exist in every operating system, but types may
vary. Environment variables can be created, edited,
saved, and deleted and give information about the
system behavior. They are declared as global i.e.
visible to everyone. For example, the environment
variable can store information about the default text
editor or browser, the path to executable files, or
the system locale and keyboard layout settings.
• Commands to be used for Environment
variables
• $ env
• It shows all the environment variables. It is an
external command and runs in a child process.
It thus lists only those variables that it has
inherited from its parent.
• By convention environment variable names
are defined in UPPER CASE.
• The set statement displays all variables
available in the current shell but the env
command displays only environment variable.
COMMON ENVIRONMENT VARIABLES

• HOME:
• The system shall initialize this variable at the time of
login to be a pathname of the user's home directory.
• LOGNAME:
• The system shall initialize this variable at the time of
login to be the user's login name. For a value of
LOGNAME to be portable across implementations of
IEEE Std 1003.1-2001, the value should be composed
of characters from the portable filename character set.
• PATH
• This variable shall represent the sequence of path prefixes that certain functions and
utilities apply in searching for an executable file known only by a filename.
• The prefixes shall be separated by a colon ( ':' ). When a non-zero-length prefix is applied
to this filename, a slash shall be inserted between the prefix and the filename. A zero-
length prefix is a legacy feature that indicates the current working directory.
• It appears as two adjacent colons ( "::" ), as an initial colon preceding the rest of the list,
or as a trailing colon following the rest of the list.
• A strictly conforming application shall use an actual pathname (such as .) to represent the
current working directory in PATH . The list shall be searched from beginning to end,
applying the filename to each prefix, until an executable file with the specified name and
appropriate execution permissions is found.
• If the pathname being sought contains a slash, the search through the path prefixes shall
not be performed. If the pathname begins with a slash, the specified path is resolved.
• If PATH is unset or is set to null, the path search is implementation-defined.
• PWD
• This variable shall represent an absolute pathname of
the current working directory. It shall not contain any
filename components of dot or dot-dot. The value is
set by the cd utility.
• SHELL
• This variable shall represent a pathname of the user's
preferred command language interpreter. If this
interpreter does not conform to the Shell Command
Language in the Shell and Utilities volume of IEEE.
• TERM
• This variable shall represent the terminal type
for which output is to be prepared. This
information is used by utilities and application
programs wishing to exploit special
capabilities specific to a terminal. The format
and allowable values of this environment
variable are unspecified.
Local Variables:
• They are more restricted in the scope. A variable declared as local is
one that is visible only within the block of code in which it appears. It
has local "scope". A local variable can be converted to an
environment variable using shell export statement.
•  
• The user defined variables are by default local in scope.
• $ Variable_name = value
• is used to create and initialize the variable. Variable can be made
global by exporting it like:
• $ export Variable_name
• Whenever a variable is exported it becomes the part of the
environment.

Das könnte Ihnen auch gefallen