OSDN Git Service

d24a792c0f21f571824c8577d2c28079446a1015
[linuxjm/LDP_man-pages.git] / original / man7 / environ.7
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 2014-08-19 "Linux" "Linux Programmer's Manual"
35 .SH NAME
36 environ \- user environment
37 .SH SYNOPSIS
38 .nf
39 .BI "extern char **" environ ;
40 .br
41 .fi
42 .SH DESCRIPTION
43 The variable
44 .I environ
45 points to an array of pointers to strings called the "environment".
46 The last pointer in this array has the value NULL.
47 (This variable must be declared in the user program,
48 but is declared in the header file
49 .I <unistd.h>
50 if the
51 .B _GNU_SOURCE
52 feature test macro is defined.)
53 This array of strings is made available to the process by the
54 .BR exec (3)
55 call that started the process.
56
57 By convention the strings in
58 .I environ
59 have the form "\fIname\fP\fB=\fP\fIvalue\fP".
60 Common examples are:
61 .TP
62 .B USER
63 The name of the logged-in user (used by some BSD-derived programs).
64 .TP
65 .B LOGNAME
66 The name of the logged-in user (used by some System-V derived programs).
67 .TP
68 .B HOME
69 A user's login directory, set by
70 .BR login (1)
71 from the password file
72 .BR passwd (5).
73 .TP
74 .B LANG
75 The name of a locale to use for locale categories when not overridden
76 by
77 .B LC_ALL
78 or more specific environment variables such as
79 .BR LC_COLLATE ,
80 .BR LC_CTYPE ,
81 .BR LC_MESSAGES ,
82 .BR LC_MONETARY ,
83 .BR LC_NUMERIC ,
84 and
85 .BR LC_TIME
86 (see
87 .BR locale (7)
88 for further details of the
89 .BR LC_*
90 environment variables).
91 .TP
92 .B PATH
93 The sequence of directory prefixes that
94 .BR sh (1)
95 and many other
96 programs apply in searching for a file known by an incomplete pathname.
97 The prefixes are separated by \(aq\fB:\fP\(aq.
98 (Similarly one has
99 .B CDPATH
100 used by some shells to find the target
101 of a change directory command,
102 .B MANPATH
103 used by
104 .BR man (1)
105 to find manual pages, and so on)
106 .TP
107 .B PWD
108 The current working directory.
109 Set by some shells.
110 .TP
111 .B SHELL
112 The pathname of the user's login shell.
113 .TP
114 .B TERM
115 The terminal type for which output is to be prepared.
116 .TP
117 .B PAGER
118 The user's preferred utility to display text files.
119 .TP
120 .BR EDITOR / VISUAL
121 The user's preferred utility to edit text files.
122 .\" .TP
123 .\" .B BROWSER
124 .\" The user's preferred utility to browse URLs. Sequence of colon-separated
125 .\" browser commands. See http://www.catb.org/~esr/BROWSER/ .
126 .PP
127 Further names may be placed in the environment by the
128 .I export
129 command and "name=value" in
130 .BR sh (1),
131 or by the
132 .I setenv
133 command if you use
134 .BR csh (1).
135 Arguments may also be placed in the
136 environment at the point of an
137 .BR exec (3).
138 A C program can manipulate its environment using the functions
139 .BR getenv (3),
140 .BR putenv (3),
141 .BR setenv (3),
142 and
143 .BR unsetenv (3).
144
145 Note that the behavior of many programs and library routines is
146 influenced by the presence or value of certain environment variables.
147 A random collection:
148 .LP
149 The variables
150 .BR LANG ", " LANGUAGE ", " NLSPATH ", " LOCPATH ", "
151 .BR LC_ALL ", " LC_MESSAGES ", "
152 and so on influence locale handling; see
153 .BR catopen (3),
154 .BR gettext (3),
155 and
156 .BR locale (7).
157 .LP
158 .B TMPDIR
159 influences the path prefix of names created by
160 .BR tmpnam (3)
161 and other routines, and the temporary directory used by
162 .BR sort (1)
163 and other programs.
164 .LP
165 .BR LD_LIBRARY_PATH ", " LD_PRELOAD
166 and other LD_* variables influence
167 the behavior of the dynamic loader/linker.
168 .LP
169 .B POSIXLY_CORRECT
170 makes certain programs and library routines follow
171 the prescriptions of POSIX.
172 .LP
173 The behavior of
174 .BR malloc (3)
175 is influenced by
176 .B MALLOC_*
177 variables.
178 .LP
179 The variable
180 .B HOSTALIASES
181 gives the name of a file containing aliases
182 to be used with
183 .BR gethostbyname (3).
184 .LP
185 .BR TZ " and " TZDIR
186 give timezone information used by
187 .BR tzset (3)
188 and through that by functions like
189 .BR ctime (3),
190 .BR localtime (3),
191 .BR mktime (3),
192 .BR strftime (3).
193 See also
194 .BR tzselect (8).
195 .LP
196 .B TERMCAP
197 gives information on how to address a given terminal
198 (or gives the name of a file containing such information).
199 .LP
200 .BR COLUMNS " and " LINES
201 tell applications about the window size, possibly overriding the actual size.
202 .LP
203 .BR PRINTER " or " LPDEST
204 may specify the desired printer to use.
205 See
206 .BR lpr (1).
207 .LP
208 Etc.
209 .SH BUGS
210 Clearly there is a security risk here.
211 Many a system command has been
212 tricked into mischief by a user who specified unusual values for
213 .BR IFS " or " LD_LIBRARY_PATH .
214
215 There is also the risk of name space pollution.
216 Programs like
217 .I make
218 and
219 .I autoconf
220 allow overriding of default utility names from the
221 environment with similarly named variables in all caps.
222 Thus one uses
223 .B CC
224 to select the desired C compiler (and similarly
225 .BR MAKE ,
226 .BR AR ,
227 .BR AS ,
228 .BR FC ,
229 .BR LD ,
230 .BR LEX ,
231 .BR RM ,
232 .BR YACC ,
233 etc.).
234 However, in some traditional uses such an environment variable
235 gives options for the program instead of a pathname.
236 Thus, one has
237 .BR MORE ,
238 .BR LESS ,
239 and
240 .BR GZIP .
241 Such usage is considered mistaken, and to be avoided in new
242 programs.
243 The authors of
244 .I gzip
245 should consider renaming their option to
246 .BR GZIP_OPT .
247 .SH SEE ALSO
248 .BR env (1),
249 .BR bash (1),
250 .BR csh (1),
251 .BR login (1),
252 .BR printenv (1),
253 .BR sh (1),
254 .BR tcsh (1),
255 .BR execve (2),
256 .BR clearenv (3),
257 .BR exec (3),
258 .BR getenv (3),
259 .BR putenv (3),
260 .BR setenv (3),
261 .BR unsetenv (3),
262 .BR locale (7),
263 .BR ld.so (8)
264 .SH COLOPHON
265 This page is part of release 3.79 of the Linux
266 .I man-pages
267 project.
268 A description of the project,
269 information about reporting bugs,
270 and the latest version of this page,
271 can be found at
272 \%http://www.kernel.org/doc/man\-pages/.