OSDN Git Service

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