1ENVIRON(7)                 Linux Programmer's Manual                ENVIRON(7)
2
3
4

NAME

6       environ - user environment
7

SYNOPSIS

9       extern char **environ;
10

DESCRIPTION

12       The  variable  environ points to an array of pointers to strings called
13       the "environment".  The last pointer in this array has the value  NULL.
14       This array of strings is made available to the process by the execve(2)
15       call when a new program is started.  When a child  process  is  created
16       via fork(2), it inherits a copy of its parent's environment.
17
18       By  convention, the strings in environ have the form "name=value".  The
19       name is case-sensitive and may not  contain  the  character  "=".   The
20       value  can  be  anything that can be represented as a string.  The name
21       and the value may not contain an embedded null byte ('\0'), since  this
22       is assumed to terminate the string.
23
24       Environment  variables  may be placed in the shell's environment by the
25       export command in sh(1), or by the setenv command if you use csh(1).
26
27       The initial environment of the shell is populated in various ways, such
28       as  definitions  from /etc/environment that are processed by pam_env(8)
29       for all users at login time (on systems that employ pam(8)).  In  addi‐
30       tion,  various  shell  initialization  scripts, such as the system-wide
31       /etc/profile script and per-user  initializations  script  may  include
32       commands  that add variables to the shell's environment; see the manual
33       page of your preferred shell for details.
34
35       Bourne-style shells support the syntax
36
37           NAME=value command
38
39       to create an environment variable definition only in the scope  of  the
40       process  that  executes  command.  Multiple variable definitions, sepa‐
41       rated by white space, may precede command.
42
43       Arguments may also be placed in the environment  at  the  point  of  an
44       exec(3).   A  C  program can manipulate its environment using the func‐
45       tions getenv(3), putenv(3), setenv(3), and unsetenv(3).
46
47       What follows is a list of environment variables  typically  seen  on  a
48       system.   This  list  is  incomplete and includes only common variables
49       seen by average users in their day-to-day routine.   Environment  vari‐
50       ables  specific  to  a particular program or library function are docu‐
51       mented in the ENVIRONMENT section of the appropriate manual page.
52
53       USER   The name of the logged-in user (used by  some  BSD-derived  pro‐
54              grams).  Set at login time, see section NOTES below.
55
56       LOGNAME
57              The  name  of  the logged-in user (used by some System-V derived
58              programs).  Set at login time, see section NOTES below.
59
60       HOME   A user's login directory.  Set at login time, see section  NOTES
61              below.
62
63       LANG   The name of a locale to use for locale categories when not over‐
64              ridden by LC_ALL or more specific environment variables such  as
65              LC_COLLATE,  LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and
66              LC_TIME (see locale(7) for further details of the LC_*  environ‐
67              ment variables).
68
69       PATH   The  sequence  of  directory  prefixes that sh(1) and many other
70              programs employ when searching for an executable  file  that  is
71              specified  as  a simple filename (i.a., a pathname that contains
72              no slashes).  The prefixes are separated  by  colons  (:).   The
73              list  of prefixes is searched from beginning to end, by checking
74              the pathname formed by concatenating a prefix, a slash, and  the
75              filename, until a file with execute permission is found.
76
77              As  a legacy feature, a zero-length prefix (specified as two ad‐
78              jacent colons, or an initial or  terminating  colon)  is  inter‐
79              preted  to  mean the current working directory.  However, use of
80              this feature is deprecated, and POSIX notes  that  a  conforming
81              application shall use an explicit pathname (e.g., .)  to specify
82              the current working directory.
83
84              Analogously to PATH, one has CDPATH used by some shells to  find
85              the target of a change directory command, MANPATH used by man(1)
86              to find manual pages, and so on.
87
88       PWD    The current working directory.  Set by some shells.
89
90       SHELL  The absolute pathname of the user's login shell.  Set  at  login
91              time, see section NOTES below.
92
93       TERM   The terminal type for which output is to be prepared.
94
95       PAGER  The  user's preferred utility to display text files.  Any string
96              acceptable as a command-string  operand  to  the  sh -c  command
97              shall  be  valid.  If PAGER is null or is not set, then applica‐
98              tions that launch a pager will default  to  a  program  such  as
99              less(1) or more(1).
100
101       EDITOR/VISUAL
102              The user's preferred utility to edit text files.  Any string ac‐
103              ceptable as a command_string operand to the sh -c command  shall
104              be valid.
105
106       Note  that the behavior of many programs and library routines is influ‐
107       enced by the presence or value of certain environment variables.  Exam‐
108       ples include the following:
109
110       *  The variables LANG, LANGUAGE, NLSPATH, LOCPATH, LC_ALL, LC_MESSAGES,
111          and so on influence locale handling; see catopen(3), gettext(3), and
112          locale(7).
113
114       *  TMPDIR influences the path prefix of names created by tempnam(3) and
115          other routines, and the temporary  directory  used  by  sort(1)  and
116          other programs.
117
118       *  LD_LIBRARY_PATH,  LD_PRELOAD, and other LD_* variables influence the
119          behavior of the dynamic loader/linker.  See also ld.so(8).
120
121       *  POSIXLY_CORRECT makes certain programs and library  routines  follow
122          the prescriptions of POSIX.
123
124       *  The behavior of malloc(3) is influenced by MALLOC_* variables.
125
126       *  The variable HOSTALIASES gives the name of a file containing aliases
127          to be used with gethostbyname(3).
128
129       *  TZ and TZDIR give timezone information used by tzset(3) and  through
130          that  by  functions  like  ctime(3),  localtime(3), mktime(3), strf‐
131          time(3).  See also tzselect(8).
132
133       *  TERMCAP gives information on how to address  a  given  terminal  (or
134          gives the name of a file containing such information).
135
136       *  COLUMNS  and LINES tell applications about the window size, possibly
137          overriding the actual size.
138
139       *  PRINTER or LPDEST may specify  the  desired  printer  to  use.   See
140          lpr(1).
141

NOTES

143       Historically and by standard, environ must be declared in the user pro‐
144       gram.  However, as a (nonstandard) programmer convenience,  environ  is
145       declared  in the header file <unistd.h> if the _GNU_SOURCE feature test
146       macro is defined (see feature_test_macros(7)).
147
148       The prctl(2) PR_SET_MM_ENV_START and PR_SET_MM_ENV_END  operations  can
149       be used to control the location of the process's environment.
150
151       The  HOME,  LOGNAME, SHELL, and USER variables are set when the user is
152       changed via a session management interface, typically by a program such
153       as  login(1)  from  a user database (such as passwd(5)).  (Switching to
154       the root user using su(1) may result in a mixed environment where  LOG‐
155       NAME and USER are retained from old user; see the su(1) manual page.)
156

BUGS

158       Clearly  there is a security risk here.  Many a system command has been
159       tricked into mischief by a user who specified unusual values for IFS or
160       LD_LIBRARY_PATH.
161
162       There is also the risk of name space pollution.  Programs like make and
163       autoconf allow overriding of default utility names from the environment
164       with similarly named variables in all caps.  Thus one uses CC to select
165       the desired C compiler (and similarly MAKE, AR, AS, FC,  LD,  LEX,  RM,
166       YACC,  etc.).   However,  in  some traditional uses such an environment
167       variable gives options for the program instead of  a  pathname.   Thus,
168       one  has  MORE  and LESS.  Such usage is considered mistaken, and to be
169       avoided in new programs.
170

SEE ALSO

172       bash(1), csh(1), env(1), login(1), printenv(1), sh(1), su(1),  tcsh(1),
173       execve(2),  clearenv(3),  exec(3), getenv(3), putenv(3), setenv(3), un‐
174       setenv(3), locale(7), ld.so(8), pam_env(8)
175

COLOPHON

177       This page is part of release 5.13 of the Linux  man-pages  project.   A
178       description  of  the project, information about reporting bugs, and the
179       latest    version    of    this    page,    can     be     found     at
180       https://www.kernel.org/doc/man-pages/.
181
182
183
184Linux                             2021-03-22                        ENVIRON(7)
Impressum