# man > environ(7)

[_environ_(7)](https://www.chedong.com/phpMan.php/man/environ/7/markdown)                        Miscellaneous Information Manual                        [_environ_(7)](https://www.chedong.com/phpMan.php/man/environ/7/markdown)

## NAME
       environ - user environment

## SYNOPSIS
       **extern char **_**environ_**;**

## DESCRIPTION
       The variable _environ_ points to an array of pointers to strings called the "environment".  The
       last  pointer  in  this array has the value NULL.  This array of strings is made available to
       the process by the [**execve**(2)](https://www.chedong.com/phpMan.php/man/execve/2/markdown) call when a new program is started.  When  a  child  process  is
       created via [**fork**(2)](https://www.chedong.com/phpMan.php/man/fork/2/markdown), it inherits a _copy_ of its parent's environment.

       By convention, the strings in _environ_ have the form "_name_**=_**value_".  The name is case-sensitive
       and  may not contain the character "**=**".  The value can be anything that can be represented as
       a string.  The name and the value may not contain an embedded null byte ('\0'), since this is
       assumed to terminate the string.

       Environment variables may be placed in the shell's  environment  by  the  _export_  command  in
       [**sh**(1)](https://www.chedong.com/phpMan.php/man/sh/1/markdown), or by the _setenv_ command if you use [**csh**(1)](https://www.chedong.com/phpMan.php/man/csh/1/markdown).

       The  initial  environment of the shell is populated in various ways, such as definitions from
       _/etc/environment_ that are processed by [**pam_env**(8)](https://www.chedong.com/phpMan.php/man/pamenv/8/markdown) for all users at  login  time  (on  systems
       that  employ [**pam**(8)](https://www.chedong.com/phpMan.php/man/pam/8/markdown)).  In addition, various shell initialization scripts, such as the system-
       wide _/etc/profile_ script and per-user initializations script may include  commands  that  add
       variables  to  the  shell's  environment; see the manual page of your preferred shell for de‐
       tails.

       Bourne-style shells support the syntax

           NAME=value command

       to create an environment variable definition only in the scope of the process  that  executes
       _command_.  Multiple variable definitions, separated by white space, may precede _command_.

       Arguments  may also be placed in the environment at the point of an [**exec**(3)](https://www.chedong.com/phpMan.php/man/exec/3/markdown).  A C program can
       manipulate its environment using the  functions  [**getenv**(3)](https://www.chedong.com/phpMan.php/man/getenv/3/markdown),  [**putenv**(3)](https://www.chedong.com/phpMan.php/man/putenv/3/markdown),  [**setenv**(3)](https://www.chedong.com/phpMan.php/man/setenv/3/markdown),  and  **un‐**
       [**setenv**(3)](https://www.chedong.com/phpMan.php/man/setenv/3/markdown).

       What follows is a list of environment variables typically seen on a system.  This list is in‐
       complete  and  includes  only common variables seen by average users in their day-to-day rou‐
       tine.  Environment variables specific to a particular program or library function  are  docu‐
       mented in the ENVIRONMENT section of the appropriate manual page.

       **USER   **The  name  of  the  logged-in  user (used by some BSD-derived programs).  Set at login
              time, see section NOTES below.

       **LOGNAME**
              The name of the logged-in user (used by some System-V derived programs).  Set at login
              time, see section NOTES below.

       **HOME   **A user's login directory.  Set at login time, see section NOTES below.

       **LANG   **The name of a locale to use for locale categories when not  overridden  by  **LC_ALL  **or
              more specific environment variables such as **LC_COLLATE**, **LC_CTYPE**, **LC_MESSAGES**, **LC_MON‐**
              **ETARY**, **LC_NUMERIC**, and **LC_TIME **(see [**locale**(7)](https://www.chedong.com/phpMan.php/man/locale/7/markdown) for further details of the **LC_* **environ‐
              ment variables).

       **PATH   **The  sequence  of  directory  prefixes  that [**sh**(1)](https://www.chedong.com/phpMan.php/man/sh/1/markdown) and many other programs employ when
              searching for an executable file that is specified as a simple filename (i.a., a path‐
              name that contains no slashes).  The prefixes are separated by colons (**:**).   The  list
              of prefixes is searched from beginning to end, by checking the pathname formed by con‐
              catenating  a  prefix, a slash, and the filename, until a file with execute permission
              is found.

              As a legacy feature, a zero-length prefix (specified as two  adjacent  colons,  or  an
              initial  or  terminating  colon) is interpreted to mean the current working directory.
              However, use of this feature is deprecated, and POSIX notes that a conforming applica‐
              tion shall use an explicit pathname (e.g., _._)  to specify the current  working  direc‐
              tory.

              Analogously to **PATH**, one has **CDPATH **used by some shells to find the target of a change
              directory command, **MANPATH **used by [**man**(1)](https://www.chedong.com/phpMan.php/man/man/1/markdown) to find manual pages, and so on.

       **PWD    **Absolute path to the current working directory; required to be partially canonical (no
              _._ or _.._ components).

       **SHELL  **The absolute pathname of the user's login shell.  Set at login time, see section NOTES
              below.

       **TERM   **The terminal type for which output is to be prepared.

       **PAGER  **The  user's  preferred utility to display text files.  Any string acceptable as a com‐
              mand-string operand to the _sh_ _-c_ command shall be valid.  If **PAGER **is null or  is  not
              set,  then  applications that launch a pager will default to a program such as [**less**(1)](https://www.chedong.com/phpMan.php/man/less/1/markdown)
              or [**more**(1)](https://www.chedong.com/phpMan.php/man/more/1/markdown).

       **EDITOR**/**VISUAL**
              The user's preferred utility to edit text files.  Any  string  acceptable  as  a  com‐
              mand_string operand to the _sh_ _-c_ command shall be valid.

       Note that the behavior of many programs and library routines is influenced by the presence or
       value of certain environment variables.  Examples include the following:

       •  The  variables  **LANG**, **LANGUAGE**, **NLSPATH**, **LOCPATH**, **LC_ALL**, **LC_MESSAGES**, and so on influence
          locale handling; see [**catopen**(3)](https://www.chedong.com/phpMan.php/man/catopen/3/markdown), [**gettext**(3)](https://www.chedong.com/phpMan.php/man/gettext/3/markdown), and [**locale**(7)](https://www.chedong.com/phpMan.php/man/locale/7/markdown).

       •  **TMPDIR **influences the path prefix of names created by [**tempnam**(3)](https://www.chedong.com/phpMan.php/man/tempnam/3/markdown) and other  routines,  and
          the temporary directory used by [**sort**(1)](https://www.chedong.com/phpMan.php/man/sort/1/markdown) and other programs.

       •  **LD_LIBRARY_PATH**,  **LD_PRELOAD**,  and  other **LD_* **variables influence the behavior of the dy‐
          namic loader/linker.  See also [**ld.so**(8)](https://www.chedong.com/phpMan.php/man/ld.so/8/markdown).

       •  **POSIXLY_CORRECT **makes certain programs and library routines follow  the  prescriptions  of
          POSIX.

       •  The behavior of [**malloc**(3)](https://www.chedong.com/phpMan.php/man/malloc/3/markdown) is influenced by **MALLOC_* **variables.

       •  The variable **HOSTALIASES **gives the name of a file containing aliases to be used with **geth‐**
          [**ostbyname**(3)](https://www.chedong.com/phpMan.php/man/ostbyname/3/markdown).

       •  **TZ **and **TZDIR **give timezone information used by [**tzset**(3)](https://www.chedong.com/phpMan.php/man/tzset/3/markdown) and through that by functions like
          [**ctime**(3)](https://www.chedong.com/phpMan.php/man/ctime/3/markdown), [**localtime**(3)](https://www.chedong.com/phpMan.php/man/localtime/3/markdown), [**mktime**(3)](https://www.chedong.com/phpMan.php/man/mktime/3/markdown), [**strftime**(3)](https://www.chedong.com/phpMan.php/man/strftime/3/markdown).  See also [**tzselect**(8)](https://www.chedong.com/phpMan.php/man/tzselect/8/markdown).

       •  **TERMCAP  **gives information on how to address a given terminal (or gives the name of a file
          containing such information).

       •  **COLUMNS **and **LINES **tell applications about the window size, possibly overriding the  actual
          size.

       •  **PRINTER **or **LPDEST **may specify the desired printer to use.  See [**lpr**(1)](https://www.chedong.com/phpMan.php/man/lpr/1/markdown).

## NOTES
       Historically  and  by  standard, _environ_ must be declared in the user program.  However, as a
       (nonstandard) programmer convenience, _environ_ is declared in the header  file  _<unistd.h>_  if
       the **_GNU_SOURCE **feature test macro is defined (see [**feature_test_macros**(7)](https://www.chedong.com/phpMan.php/man/featuretestmacros/7/markdown)).

       The  [**prctl**(2)](https://www.chedong.com/phpMan.php/man/prctl/2/markdown) **PR_SET_MM_ENV_START **and **PR_SET_MM_ENV_END **operations can be used to control the
       location of the process's environment.

       The **HOME**, **LOGNAME**, **SHELL**, and **USER **variables are set when the user is changed via  a  session
       management  interface,  typically by a program such as [**login**(1)](https://www.chedong.com/phpMan.php/man/login/1/markdown) from a user database (such as
       [**passwd**(5)](https://www.chedong.com/phpMan.php/man/passwd/5/markdown)).  (Switching to the root user using [**su**(1)](https://www.chedong.com/phpMan.php/man/su/1/markdown) may result in a mixed environment  where
       **LOGNAME **and **USER **are retained from old user; see the [**su**(1)](https://www.chedong.com/phpMan.php/man/su/1/markdown) manual page.)

## BUGS
       Clearly  there is a security risk here.  Many a system command has been tricked into mischief
       by a user who specified unusual values for **IFS **or **LD_LIBRARY_PATH**.

       There is also the risk of name space pollution.  Programs like _make_ and _autoconf_ allow  over‐
       riding  of  default  utility names from the environment with similarly named variables in all
       caps.  Thus one uses **CC **to select the desired C compiler (and similarly **MAKE**, **AR**, **AS**, **FC**, **LD**,
       **LEX**, **RM**, **YACC**, etc.).  However, in some traditional uses such an environment  variable  gives
       options  for  the program instead of a pathname.  Thus, one has **MORE **and **LESS**.  Such usage is
       considered mistaken, and to be avoided in new programs.

## SEE ALSO
       [**bash**(1)](https://www.chedong.com/phpMan.php/man/bash/1/markdown),  [**csh**(1)](https://www.chedong.com/phpMan.php/man/csh/1/markdown),  [**env**(1)](https://www.chedong.com/phpMan.php/man/env/1/markdown),  [**login**(1)](https://www.chedong.com/phpMan.php/man/login/1/markdown),  [**printenv**(1)](https://www.chedong.com/phpMan.php/man/printenv/1/markdown),   [**sh**(1)](https://www.chedong.com/phpMan.php/man/sh/1/markdown),   [**su**(1)](https://www.chedong.com/phpMan.php/man/su/1/markdown),   [**tcsh**(1)](https://www.chedong.com/phpMan.php/man/tcsh/1/markdown),   [**execve**(2)](https://www.chedong.com/phpMan.php/man/execve/2/markdown),
       [**clearenv**(3)](https://www.chedong.com/phpMan.php/man/clearenv/3/markdown),  [**exec**(3)](https://www.chedong.com/phpMan.php/man/exec/3/markdown),  [**getenv**(3)](https://www.chedong.com/phpMan.php/man/getenv/3/markdown),  [**putenv**(3)](https://www.chedong.com/phpMan.php/man/putenv/3/markdown),  [**setenv**(3)](https://www.chedong.com/phpMan.php/man/setenv/3/markdown),  [**unsetenv**(3)](https://www.chedong.com/phpMan.php/man/unsetenv/3/markdown), [**locale**(7)](https://www.chedong.com/phpMan.php/man/locale/7/markdown), [**ld.so**(8)](https://www.chedong.com/phpMan.php/man/ld.so/8/markdown),
       [**pam_env**(8)](https://www.chedong.com/phpMan.php/man/pamenv/8/markdown)

Linux man-pages 6.7                          2023-10-31                                   [_environ_(7)](https://www.chedong.com/phpMan.php/man/environ/7/markdown)
