1ENVIRON(7) Linux Programmer's Manual ENVIRON(7)
2
3
4
6 environ - user environment
7
9 extern char **environ;
10
12 The variable environ points to an array of strings called the `environ‐
13 ment'. (This variable must be declared in the user program, but is
14 declared in the header file <unistd.h> in case the header files came
15 from libc4 or libc5, and in case they came from glibc and _GNU_SOURCE
16 was defined.) This array of strings is made available to the process
17 by the exec(3) call that started the process. By convention these
18 strings have the form `name=value'. Common examples are:
19
20 USER The name of the logged-in user (used by some BSD-derived pro‐
21 grams).
22
23 LOGNAME
24 The name of the logged-in user (used by some System-V derived
25 programs).
26
27 HOME A user's login directory, set by login(1) from the password file
28 passwd(5).
29
30 LANG The name of a locale to use for locale categories when not over‐
31 ridden by LC_ALL or more specific environment variables like
32 LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC,
33 LC_TIME, cf. locale(5).
34
35 PATH The sequence of directory prefixes that sh(1) and many other
36 programs apply in searching for a file known by an incomplete
37 pathname. The prefixes are separated by `:'. (Similarly one
38 has CDPATH used by some shells to find the target of a change
39 directory command, MANPATH used by man(1) to find manual pages,
40 etc.)
41
42 PWD The current working directory. Set by some shells.
43
44 SHELL The pathname of the user's login shell.
45
46 TERM The terminal type for which output is to be prepared.
47
48 PAGER The user's preferred utility to display text files.
49
50 EDITOR/VISUAL
51 The user's preferred utility to edit text files.
52
53 Further names may be placed in the environment by the export command
54 and `name=value' in sh(1), or by the setenv command if you use csh(1).
55 Arguments may also be placed in the environment at the point of an
56 exec(3). A C program can manipulate its environment using the func‐
57 tions getenv(3), putenv(3), setenv(3), and unsetenv(3).
58
59 Note that the behaviour of many programs and library routines is influ‐
60 enced by the presence or value of certain environment variables. A
61 random collection:
62
63 The variables LANG, LANGUAGE, NLSPATH, LOCPATH, LC_ALL, LC_MESSAGES,
64 etc. influence locale handling, cf. locale(5).
65
66 TMPDIR influences the path prefix of names created by tmpnam(3) and
67 other routines, the temporary directory used by sort(1) and other pro‐
68 grams, etc.
69
70 LD_LIBRARY_PATH, LD_PRELOAD and other LD_* variables influence the be‐
71 haviour of the dynamic loader/linker.
72
73 POSIXLY_CORRECT makes certain programs and library routines follow the
74 prescriptions of POSIX.
75
76 The behaviour of malloc(3) is influenced by MALLOC_* variables.
77
78 The variable HOSTALIASES gives the name of a file containing aliases to
79 be used with gethostbyname(3).
80
81 TZ and TZDIR give time zone information used by tzset(3) and through
82 that by functions like ctime(), localtime(), mktime(), strftime(). See
83 also tzselect(1).
84
85 TERMCAP gives information on how to address a given terminal (or gives
86 the name of a file containing such information).
87
88 COLUMNS and LINES tell applications about the window size, possibly
89 overriding the actual size.
90
91 PRINTER or LPDEST may specify the desired printer to use. See lpr(1).
92
93 Etc.
94
96 Clearly there is a security risk here. Many a system command has been
97 tricked into mischief by a user who specified unusual values for IFS or
98 LD_LIBRARY_PATH.
99
100 There is also the risk of name space pollution. Programs like make and
101 autoconf allow overriding of default utility names from the environment
102 with similarly named variables in all caps. Thus one uses CC to select
103 the desired C compiler (and similarly MAKE, AR, AS, FC, LD, LEX, RM,
104 YACC, etc.). However, in some traditional uses such an environment
105 variable gives options for the program instead of a pathname. Thus,
106 one has MORE, LESS, and GZIP. Such usage is considered mistaken, and
107 to be avoided in new programs. The authors of gzip should consider
108 renaming their option to GZIP_OPT.
109
111 bash(1), csh(1), login(1), sh(1), tcsh(1), execve(2), clearenv(3),
112 exec(3), getenv(3), putenv(3), setenv(3), unsetenv(3), locale(5)
113
114
115
116Linux 2001-12-14 ENVIRON(7)