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