mount_namespaces.7: wfix
[man-pages.git] / man7 / environ.7
blob220a7c0b6b727dd34e0391952d6437ffc71dc6cc
1 .\" Copyright (c) 1993 Michael Haardt (michael@moria.de),
2 .\"   Fri Apr  2 11:32:09 MET DST 1993
3 .\" and Andries Brouwer (aeb@cwi.nl), Fri Feb 14 21:47:50 1997.
4 .\"
5 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
6 .\" This is free documentation; you can redistribute it and/or
7 .\" modify it under the terms of the GNU General Public License as
8 .\" published by the Free Software Foundation; either version 2 of
9 .\" the License, or (at your option) any later version.
10 .\"
11 .\" The GNU General Public License's references to "object code"
12 .\" and "executables" are to be interpreted as the output of any
13 .\" document formatting or typesetting system, including
14 .\" intermediate and printed output.
15 .\"
16 .\" This manual is distributed in the hope that it will be useful,
17 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
18 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 .\" GNU General Public License for more details.
20 .\"
21 .\" You should have received a copy of the GNU General Public
22 .\" License along with this manual; if not, see
23 .\" <http://www.gnu.org/licenses/>.
24 .\" %%%LICENSE_END
25 .\"
26 .\" Modified Sun Jul 25 10:45:30 1993 by Rik Faith (faith@cs.unc.edu)
27 .\" Modified Sun Jul 21 21:25:26 1996 by Andries Brouwer (aeb@cwi.nl)
28 .\" Modified Mon Oct 21 17:47:19 1996 by Eric S. Raymond (esr@thyrsus.com)
29 .\" Modified Wed Aug 27 20:28:58 1997 by Nicolás Lichtmaier (nick@debian.org)
30 .\" Modified Mon Sep 21 00:00:26 1998 by Andries Brouwer (aeb@cwi.nl)
31 .\" Modified Wed Jan 24 06:37:24 2001 by Eric S. Raymond (esr@thyrsus.com)
32 .\" Modified Thu Dec 13 23:53:27 2001 by Martin Schulze <joey@infodrom.org>
33 .\"
34 .TH ENVIRON 7 2021-03-22 "Linux" "Linux Programmer's Manual"
35 .SH NAME
36 environ \- user environment
37 .SH SYNOPSIS
38 .nf
39 .BI "extern char **" environ ;
40 .fi
41 .SH DESCRIPTION
42 The variable
43 .I environ
44 points to an array of pointers to strings called the "environment".
45 The last pointer in this array has the value NULL.
46 This array of strings is made available to the process by the
47 .BR execve (2)
48 call when a new program is started.
49 When a child process is created via
50 .BR fork (2),
51 it inherits a
52 .I copy
53 of its parent's environment.
54 .PP
55 By convention, the strings in
56 .I environ
57 have the form "\fIname\fP\fB=\fP\fIvalue\fP".
58 The name is case-sensitive and may not contain
59 the character "\fB=\fP".
60 The value can be anything that can be represented as a string.
61 The name and the value may not contain an embedded null byte (\(aq\e0\(aq),
62 since this is assumed to terminate the string.
63 .PP
64 Environment variables may be placed in the shell's environment by the
65 .I export
66 command in
67 .BR sh (1),
68 or by the
69 .I setenv
70 command if you use
71 .BR csh (1).
72 .PP
73 The initial environment of the shell is populated in various ways,
74 such as definitions from
75 .IR /etc/environment
76 that are processed by
77 .BR pam_env (8)
78 for all users at login time (on systems that employ
79 .BR pam (8)).
80 In addition, various shell initialization scripts, such as the system-wide
81 .IR /etc/profile
82 script and per-user initializations script may include commands
83 that add variables to the shell's environment;
84 see the manual page of your preferred shell for details.
85 .PP
86 Bourne-style shells support the syntax
87 .PP
88     NAME=value command
89 .PP
90 to create an environment variable definition only in the scope
91 of the process that executes
92 .IR command .
93 Multiple variable definitions, separated by white space, may precede
94 .IR command .
95 .PP
96 Arguments may also be placed in the
97 environment at the point of an
98 .BR exec (3).
99 A C program can manipulate its environment using the functions
100 .BR getenv (3),
101 .BR putenv (3),
102 .BR setenv (3),
104 .BR unsetenv (3).
106 What follows is a list of environment variables typically seen on a
107 system.
108 This list is incomplete and includes only common variables seen
109 by average users in their day-to-day routine.
110 Environment variables specific to a particular program or library function
111 are documented in the ENVIRONMENT section of the appropriate manual page.
113 .B USER
114 The name of the logged-in user (used by some BSD-derived programs).
115 Set at login time, see section NOTES below.
117 .B LOGNAME
118 The name of the logged-in user (used by some System-V derived programs).
119 Set at login time, see section NOTES below.
121 .B HOME
122 A user's login directory.
123 Set at login time, see section NOTES below.
125 .B LANG
126 The name of a locale to use for locale categories when not overridden
128 .B LC_ALL
129 or more specific environment variables such as
130 .BR LC_COLLATE ,
131 .BR LC_CTYPE ,
132 .BR LC_MESSAGES ,
133 .BR LC_MONETARY ,
134 .BR LC_NUMERIC ,
136 .BR LC_TIME
137 (see
138 .BR locale (7)
139 for further details of the
140 .BR LC_*
141 environment variables).
143 .B PATH
144 The sequence of directory prefixes that
145 .BR sh (1)
146 and many other
147 programs employ when searching for an executable file that is specified
148 as a simple filename (i.a., a pathname that contains no slashes).
149 The prefixes are separated by colons (\fB:\fP).
150 The list of prefixes is searched from beginning to end,
151 by checking the pathname formed by concatenating
152 a prefix, a slash, and the filename,
153 until a file with execute permission is found.
155 As a legacy feature, a zero-length prefix
156 (specified as two adjacent colons, or an initial or terminating colon)
157 is interpreted to mean the current working directory.
158 However, use of this feature is deprecated,
159 and POSIX notes that a conforming application shall use
160 an explicit pathname (e.g.,
161 .IR . )
162 to specify the current working directory.
164 Analogously to
165 .BR PATH ,
166 one has
167 .B CDPATH
168 used by some shells to find the target
169 of a change directory command,
170 .B MANPATH
171 used by
172 .BR man (1)
173 to find manual pages, and so on.
175 .B PWD
176 The current working directory.
177 Set by some shells.
179 .B SHELL
180 The absolute pathname of the user's login shell.
181 Set at login time, see section NOTES below.
183 .B TERM
184 The terminal type for which output is to be prepared.
186 .B PAGER
187 The user's preferred utility to display text files.
188 Any string acceptable as a command-string operand to the
189 .I sh\ \-c
190 command shall be valid.
192 .B PAGER
193 is null or is not set,
194 then applications that launch a pager will default to a program such as
195 .BR less (1)
197 .BR more (1).
199 .BR EDITOR / VISUAL
200 The user's preferred utility to edit text files.
201 Any string acceptable as a command_string operand to the
202 .I sh\ \-c
203 command shall be valid.
204 .\" .TP
205 .\" .B BROWSER
206 .\" The user's preferred utility to browse URLs. Sequence of colon-separated
207 .\" browser commands. See http://www.catb.org/\(tiesr/BROWSER/ .
209 Note that the behavior of many programs and library routines is
210 influenced by the presence or value of certain environment variables.
211 Examples include the following:
212 .IP * 3
213 The variables
214 .BR LANG ", " LANGUAGE ", " NLSPATH ", " LOCPATH ,
215 .BR LC_ALL ", " LC_MESSAGES ,
216 and so on influence locale handling; see
217 .BR catopen (3),
218 .BR gettext (3),
220 .BR locale (7).
221 .IP *
222 .B TMPDIR
223 influences the path prefix of names created by
224 .BR tempnam (3)
225 and other routines, and the temporary directory used by
226 .BR sort (1)
227 and other programs.
228 .IP *
229 .BR LD_LIBRARY_PATH ", " LD_PRELOAD ,
230 and other
231 .BR LD_*
232 variables influence the behavior of the dynamic loader/linker.
233 See also
234 .BR ld.so (8).
235 .IP *
236 .B POSIXLY_CORRECT
237 makes certain programs and library routines follow
238 the prescriptions of POSIX.
239 .IP *
240 The behavior of
241 .BR malloc (3)
242 is influenced by
243 .B MALLOC_*
244 variables.
245 .IP *
246 The variable
247 .B HOSTALIASES
248 gives the name of a file containing aliases
249 to be used with
250 .BR gethostbyname (3).
251 .IP *
252 .BR TZ " and " TZDIR
253 give timezone information used by
254 .BR tzset (3)
255 and through that by functions like
256 .BR ctime (3),
257 .BR localtime (3),
258 .BR mktime (3),
259 .BR strftime (3).
260 See also
261 .BR tzselect (8).
262 .IP *
263 .B TERMCAP
264 gives information on how to address a given terminal
265 (or gives the name of a file containing such information).
266 .IP *
267 .BR COLUMNS " and " LINES
268 tell applications about the window size, possibly overriding the actual size.
269 .IP *
270 .BR PRINTER " or " LPDEST
271 may specify the desired printer to use.
273 .BR lpr (1).
274 .SH NOTES
275 Historically and by standard,
276 .I environ
277 must be declared in the user program.
278 However, as a (nonstandard) programmer convenience,
279 .I environ
280 is declared in the header file
281 .I <unistd.h>
282 if the
283 .B _GNU_SOURCE
284 feature test macro is defined (see
285 .BR feature_test_macros (7)).
288 .BR prctl (2)
289 .B PR_SET_MM_ENV_START
291 .B PR_SET_MM_ENV_END
292 operations can be used to control the location of the process's environment.
295 .BR HOME ,
296 .BR LOGNAME ,
297 .BR SHELL ,
299 .B USER
300 variables are set when the user is changed via a
301 session management interface, typically by a program such as
302 .BR login (1)
303 from a user database (such as
304 .BR passwd (5)).
305 (Switching to the root user using
306 .BR su (1)
307 may result in a mixed environment where
308 .B LOGNAME
310 .B USER
311 are retained from old user; see the
312 .BR su (1)
313 manual page.)
314 .SH BUGS
315 Clearly there is a security risk here.
316 Many a system command has been
317 tricked into mischief by a user who specified unusual values for
318 .BR IFS " or " LD_LIBRARY_PATH .
320 There is also the risk of name space pollution.
321 Programs like
322 .I make
324 .I autoconf
325 allow overriding of default utility names from the
326 environment with similarly named variables in all caps.
327 Thus one uses
328 .B CC
329 to select the desired C compiler (and similarly
330 .BR MAKE ,
331 .BR AR ,
332 .BR AS ,
333 .BR FC ,
334 .BR LD ,
335 .BR LEX ,
336 .BR RM ,
337 .BR YACC ,
338 etc.).
339 However, in some traditional uses such an environment variable
340 gives options for the program instead of a pathname.
341 Thus, one has
342 .B MORE
344 .BR LESS .
345 Such usage is considered mistaken, and to be avoided in new
346 programs.
347 .SH SEE ALSO
348 .BR bash (1),
349 .BR csh (1),
350 .BR env (1),
351 .BR login (1),
352 .BR printenv (1),
353 .BR sh (1),
354 .BR su (1),
355 .BR tcsh (1),
356 .BR execve (2),
357 .BR clearenv (3),
358 .BR exec (3),
359 .BR getenv (3),
360 .BR putenv (3),
361 .BR setenv (3),
362 .BR unsetenv (3),
363 .BR locale (7),
364 .BR ld.so (8),
365 .BR pam_env (8)