]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man7/environ.7
sched_setattr.2: tfix
[thirdparty/man-pages.git] / man7 / environ.7
CommitLineData
fea681da
MK
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.\"
1dd72f9c 5.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
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
c715f741
MK
22.\" License along with this manual; if not, see
23.\" <http://www.gnu.org/licenses/>.
6a8d8745 24.\" %%%LICENSE_END
c13182ef 25.\"
fea681da
MK
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)
e00c3a07 29.\" Modified Wed Aug 27 20:28:58 1997 by Nicolás Lichtmaier (nick@debian.org)
fea681da
MK
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.\"
4b8c67d9 34.TH ENVIRON 7 2017-09-15 "Linux" "Linux Programmer's Manual"
fea681da
MK
35.SH NAME
36environ \- user environment
37.SH SYNOPSIS
fea681da 38.nf
a45ebabf 39.BI "extern char **" environ ;
fea681da 40.fi
fea681da
MK
41.SH DESCRIPTION
42The variable
43.I environ
86d9ea37 44points to an array of pointers to strings called the "environment".
d6584e22 45The last pointer in this array has the value NULL.
fea681da
MK
46(This variable must be declared in the user program,
47but is declared in the header file
bd12ab88 48.I <unistd.h>
1740dfa1 49if the
fea681da 50.B _GNU_SOURCE
1740dfa1 51feature test macro is defined.)
fea681da
MK
52This array of strings is made available to the process by the
53.BR exec (3)
c13182ef 54call that started the process.
9c67b250
MK
55When a child process is created via
56.BR fork (2),
57it inherits a
58.I copy
59of its parent's environment.
5711c04f 60.PP
86d9ea37
MK
61By convention the strings in
62.I environ
2d986c92 63have the form "\fIname\fP\fB=\fP\fIvalue\fP".
c13182ef 64Common examples are:
fea681da
MK
65.TP
66.B USER
67The name of the logged-in user (used by some BSD-derived programs).
68.TP
69.B LOGNAME
70The name of the logged-in user (used by some System-V derived programs).
71.TP
72.B HOME
73A user's login directory, set by
74.BR login (1)
75from the password file
76.BR passwd (5).
77.TP
78.B LANG
79The name of a locale to use for locale categories when not overridden
c6fa0841
MK
80by
81.B LC_ALL
342a96c6 82or more specific environment variables such as
c6fa0841
MK
83.BR LC_COLLATE ,
84.BR LC_CTYPE ,
85.BR LC_MESSAGES ,
86.BR LC_MONETARY ,
87.BR LC_NUMERIC ,
d4d91728
MK
88and
89.BR LC_TIME
90(see
91.BR locale (7)
92for further details of the
93.BR LC_*
94environment variables).
fea681da
MK
95.TP
96.B PATH
60a90ecd
MK
97The sequence of directory prefixes that
98.BR sh (1)
99and many other
2d7195b8 100programs apply in searching for a file known by an incomplete pathname.
f81fb444 101The prefixes are separated by \(aq\fB:\fP\(aq.
c6fa0841
MK
102(Similarly one has
103.B CDPATH
104used by some shells to find the target
105of a change directory command,
106.B MANPATH
107used by
60a90ecd 108.BR man (1)
e5138434 109to find manual pages, and so on)
fea681da
MK
110.TP
111.B PWD
c13182ef
MK
112The current working directory.
113Set by some shells.
fea681da
MK
114.TP
115.B SHELL
2c5f1089 116The pathname of the user's login shell.
fea681da
MK
117.TP
118.B TERM
119The terminal type for which output is to be prepared.
120.TP
121.B PAGER
122The user's preferred utility to display text files.
123.TP
124.BR EDITOR / VISUAL
125The user's preferred utility to edit text files.
7739f1d4
MK
126.\" .TP
127.\" .B BROWSER
128.\" The user's preferred utility to browse URLs. Sequence of colon-separated
129.\" browser commands. See http://www.catb.org/~esr/BROWSER/ .
fea681da 130.PP
170eb741 131Names may be placed in the shell's environment by the
c6fa0841 132.I export
789fdd93 133command in
fea681da 134.BR sh (1),
c6fa0841
MK
135or by the
136.I setenv
137command if you use
fea681da 138.BR csh (1).
5711c04f 139.PP
94d3ac09
MK
140The initial environment of the shell is populated in various ways,
141such as definitions from
142.IR /etc/environment
143that are processed by
144.BR pam_env (8)
145for all users at login time (on systems that employ
146.BR pam (8)).
147In addition, various shell initialization scripts, such as the system-wide
148.IR /etc/profile
149script and per-user initializations script may include commands
150that add variables to the shell's environment;
151see the manual page of your preferred shell for details.
5711c04f 152.PP
170eb741 153Bourne-style shells support the syntax
5711c04f 154.PP
170eb741 155 NAME=value command
5711c04f 156.PP
170eb741
MK
157to create an environment variable definition only in the scope
158of the process that executes
159.IR command .
160Multiple variable definitions, separated by white space, may precede
161.IR command .
5711c04f 162.PP
fea681da
MK
163Arguments may also be placed in the
164environment at the point of an
165.BR exec (3).
166A C program can manipulate its environment using the functions
167.BR getenv (3),
168.BR putenv (3),
169.BR setenv (3),
170and
171.BR unsetenv (3).
5711c04f 172.PP
d9bfdb9c 173Note that the behavior of many programs and library routines is
fea681da 174influenced by the presence or value of certain environment variables.
09a7d9a3
MK
175Examples include the following:
176.IP * 3
fea681da 177The variables
c13182ef 178.BR LANG ", " LANGUAGE ", " NLSPATH ", " LOCPATH ", "
35478399 179.BR LC_ALL ", " LC_MESSAGES ", "
3a6d5615
MK
180and so on influence locale handling; see
181.BR catopen (3),
182.BR gettext (3),
183and
184.BR locale (7).
09a7d9a3 185.IP *
fea681da
MK
186.B TMPDIR
187influences the path prefix of names created by
a263fdde 188.BR tempnam (3)
f78ed33a 189and other routines, and the temporary directory used by
60a90ecd 190.BR sort (1)
f78ed33a 191and other programs.
09a7d9a3 192.IP *
c58a4653
MK
193.BR LD_LIBRARY_PATH ", " LD_PRELOAD ,
194and other
195.BR LD_*
196variables influence the behavior of the dynamic loader/linker.
09a7d9a3 197.IP *
fea681da
MK
198.B POSIXLY_CORRECT
199makes certain programs and library routines follow
200the prescriptions of POSIX.
09a7d9a3 201.IP *
d9bfdb9c 202The behavior of
60a90ecd 203.BR malloc (3)
c7496b03
MK
204is influenced by
205.B MALLOC_*
206variables.
09a7d9a3 207.IP *
fea681da
MK
208The variable
209.B HOSTALIASES
210gives the name of a file containing aliases
60a90ecd
MK
211to be used with
212.BR gethostbyname (3).
09a7d9a3 213.IP *
fea681da 214.BR TZ " and " TZDIR
5b0dc1ba 215give timezone information used by
fea681da
MK
216.BR tzset (3)
217and through that by functions like
2a85592a
MK
218.BR ctime (3),
219.BR localtime (3),
220.BR mktime (3),
221.BR strftime (3).
fea681da 222See also
2a85592a 223.BR tzselect (8).
09a7d9a3 224.IP *
fea681da
MK
225.B TERMCAP
226gives information on how to address a given terminal
227(or gives the name of a file containing such information).
09a7d9a3 228.IP *
fea681da
MK
229.BR COLUMNS " and " LINES
230tell applications about the window size, possibly overriding the actual size.
09a7d9a3 231.IP *
fea681da 232.BR PRINTER " or " LPDEST
c13182ef
MK
233may specify the desired printer to use.
234See
fea681da 235.BR lpr (1).
4dbcdd15
MK
236.SH NOTES
237The
238.BR prctl (2)
239.B PR_SET_MM_ENV_START
240and
241.B PR_SET_MM_ENV_END
242operations can be used to control the location of the process's environment.
fea681da 243.SH BUGS
c13182ef
MK
244Clearly there is a security risk here.
245Many a system command has been
fea681da
MK
246tricked into mischief by a user who specified unusual values for
247.BR IFS " or " LD_LIBRARY_PATH .
5711c04f 248.PP
fea681da
MK
249There is also the risk of name space pollution.
250Programs like
251.I make
252and
253.I autoconf
254allow overriding of default utility names from the
255environment with similarly named variables in all caps.
256Thus one uses
257.B CC
258to select the desired C compiler (and similarly
259.BR MAKE ,
260.BR AR ,
261.BR AS ,
262.BR FC ,
263.BR LD ,
264.BR LEX ,
265.BR RM ,
266.BR YACC ,
267etc.).
268However, in some traditional uses such an environment variable
269gives options for the program instead of a pathname.
270Thus, one has
271.BR MORE ,
272.BR LESS ,
273and
274.BR GZIP .
275Such usage is considered mistaken, and to be avoided in new
c13182ef
MK
276programs.
277The authors of
fea681da
MK
278.I gzip
279should consider renaming their option to
280.BR GZIP_OPT .
47297adb 281.SH SEE ALSO
fea681da
MK
282.BR bash (1),
283.BR csh (1),
109aa73d 284.BR env (1),
fea681da 285.BR login (1),
3f205b20 286.BR printenv (1),
fea681da
MK
287.BR sh (1),
288.BR tcsh (1),
289.BR execve (2),
290.BR clearenv (3),
291.BR exec (3),
292.BR getenv (3),
293.BR putenv (3),
294.BR setenv (3),
295.BR unsetenv (3),
3f205b20 296.BR locale (7),
6b383fbd
MK
297.BR ld.so (8),
298.BR pam_env (8)