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