441 lines
9.9 KiB
HTML
441 lines
9.9 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of ENVIRON</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>ENVIRON</H1>
|
|
Section: Linux Programmer's Manual (7)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
environ - user environment
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>extern char **</B><I>environ</I><B>;</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The variable
|
|
<I>environ</I>
|
|
|
|
points to an array of pointers to strings called the "environment".
|
|
The last pointer in this array has the value NULL.
|
|
(This variable must be declared in the user program,
|
|
but is declared in the header file
|
|
<I><<A HREF="file:///usr/include/unistd.h">unistd.h</A>></I>
|
|
|
|
if the
|
|
<B>_GNU_SOURCE</B>
|
|
|
|
feature test macro is defined.)
|
|
This array of strings is made available to the process by the
|
|
<B><A HREF="/cgi-bin/man/man2html?3+exec">exec</A></B>(3)
|
|
|
|
call that started the process.
|
|
When a child process is created via
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fork">fork</A></B>(2),
|
|
|
|
it inherits a
|
|
<I>copy</I>
|
|
|
|
of its parent's environment.
|
|
<P>
|
|
|
|
By convention the strings in
|
|
<I>environ</I>
|
|
|
|
have the form "<I>name</I><B>=</B><I>value</I>".
|
|
Common examples are:
|
|
<DL COMPACT>
|
|
<DT id="1"><B>USER</B>
|
|
|
|
<DD>
|
|
The name of the logged-in user (used by some BSD-derived programs).
|
|
<DT id="2"><B>LOGNAME</B>
|
|
|
|
<DD>
|
|
The name of the logged-in user (used by some System-V derived programs).
|
|
<DT id="3"><B>HOME</B>
|
|
|
|
<DD>
|
|
A user's login directory, set by
|
|
<B><A HREF="/cgi-bin/man/man2html?1+login">login</A></B>(1)
|
|
|
|
from the password file
|
|
<B><A HREF="/cgi-bin/man/man2html?5+passwd">passwd</A></B>(5).
|
|
|
|
<DT id="4"><B>LANG</B>
|
|
|
|
<DD>
|
|
The name of a locale to use for locale categories when not overridden
|
|
by
|
|
<B>LC_ALL</B>
|
|
|
|
or more specific environment variables such as
|
|
<B>LC_COLLATE</B>,
|
|
|
|
<B>LC_CTYPE</B>,
|
|
|
|
<B>LC_MESSAGES</B>,
|
|
|
|
<B>LC_MONETARY</B>,
|
|
|
|
<B>LC_NUMERIC</B>,
|
|
|
|
and
|
|
<B>LC_TIME</B>
|
|
|
|
(see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+locale">locale</A></B>(7)
|
|
|
|
for further details of the
|
|
<B>LC_*</B>
|
|
|
|
environment variables).
|
|
<DT id="5"><B>PATH</B>
|
|
|
|
<DD>
|
|
The sequence of directory prefixes that
|
|
<B><A HREF="/cgi-bin/man/man2html?1+sh">sh</A></B>(1)
|
|
|
|
and many other
|
|
programs apply in searching for a file known by an incomplete pathname.
|
|
The prefixes are separated by '<B>:</B>'.
|
|
(Similarly one has
|
|
<B>CDPATH</B>
|
|
|
|
used by some shells to find the target
|
|
of a change directory command,
|
|
<B>MANPATH</B>
|
|
|
|
used by
|
|
<B><A HREF="/cgi-bin/man/man2html?1+man">man</A></B>(1)
|
|
|
|
to find manual pages, and so on)
|
|
<DT id="6"><B>PWD</B>
|
|
|
|
<DD>
|
|
The current working directory.
|
|
Set by some shells.
|
|
<DT id="7"><B>SHELL</B>
|
|
|
|
<DD>
|
|
The pathname of the user's login shell.
|
|
<DT id="8"><B>TERM</B>
|
|
|
|
<DD>
|
|
The terminal type for which output is to be prepared.
|
|
<DT id="9"><B>PAGER</B>
|
|
|
|
<DD>
|
|
The user's preferred utility to display text files.
|
|
<DT id="10"><B>EDITOR</B>/<B>VISUAL</B>
|
|
|
|
<DD>
|
|
The user's preferred utility to edit text files.
|
|
|
|
|
|
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
Names may be placed in the shell's environment by the
|
|
<I>export</I>
|
|
|
|
command in
|
|
<B><A HREF="/cgi-bin/man/man2html?1+sh">sh</A></B>(1),
|
|
|
|
or by the
|
|
<I>setenv</I>
|
|
|
|
command if you use
|
|
<B><A HREF="/cgi-bin/man/man2html?1+csh">csh</A></B>(1).
|
|
|
|
<P>
|
|
|
|
The initial environment of the shell is populated in various ways,
|
|
such as definitions from
|
|
<I>/etc/environment</I>
|
|
|
|
that are processed by
|
|
<B><A HREF="/cgi-bin/man/man2html?8+pam_env">pam_env</A></B>(8)
|
|
|
|
for all users at login time (on systems that employ
|
|
<B><A HREF="/cgi-bin/man/man2html?8+pam">pam</A></B>(8)).
|
|
|
|
In addition, various shell initialization scripts, such as the system-wide
|
|
<I>/etc/profile</I>
|
|
|
|
script and per-user initializations script may include commands
|
|
that add variables to the shell's environment;
|
|
see the manual page of your preferred shell for details.
|
|
<P>
|
|
|
|
Bourne-style shells support the syntax
|
|
<P>
|
|
|
|
<BR> NAME=value command
|
|
<P>
|
|
|
|
to create an environment variable definition only in the scope
|
|
of the process that executes
|
|
<I>command</I>.
|
|
|
|
Multiple variable definitions, separated by white space, may precede
|
|
<I>command</I>.
|
|
|
|
<P>
|
|
|
|
Arguments may also be placed in the
|
|
environment at the point of an
|
|
<B><A HREF="/cgi-bin/man/man2html?3+exec">exec</A></B>(3).
|
|
|
|
A C program can manipulate its environment using the functions
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getenv">getenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+putenv">putenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setenv">setenv</A></B>(3),
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?3+unsetenv">unsetenv</A></B>(3).
|
|
|
|
<P>
|
|
|
|
Note that the behavior of many programs and library routines is
|
|
influenced by the presence or value of certain environment variables.
|
|
Examples include the following:
|
|
<DL COMPACT>
|
|
<DT id="11">*<DD>
|
|
The variables
|
|
<B>LANG</B>, <B>LANGUAGE</B>, <B>NLSPATH</B>, <B>LOCPATH</B>,
|
|
|
|
<B>LC_ALL</B>, <B>LC_MESSAGES</B>,
|
|
|
|
and so on influence locale handling; see
|
|
<B><A HREF="/cgi-bin/man/man2html?3+catopen">catopen</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+gettext">gettext</A></B>(3),
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?7+locale">locale</A></B>(7).
|
|
|
|
<DT id="12">*<DD>
|
|
<B>TMPDIR</B>
|
|
|
|
influences the path prefix of names created by
|
|
<B><A HREF="/cgi-bin/man/man2html?3+tempnam">tempnam</A></B>(3)
|
|
|
|
and other routines, and the temporary directory used by
|
|
<B><A HREF="/cgi-bin/man/man2html?1+sort">sort</A></B>(1)
|
|
|
|
and other programs.
|
|
<DT id="13">*<DD>
|
|
<B>LD_LIBRARY_PATH</B>, <B>LD_PRELOAD</B>,
|
|
|
|
and other
|
|
<B>LD_*</B>
|
|
|
|
variables influence the behavior of the dynamic loader/linker.
|
|
<DT id="14">*<DD>
|
|
<B>POSIXLY_CORRECT</B>
|
|
|
|
makes certain programs and library routines follow
|
|
the prescriptions of POSIX.
|
|
<DT id="15">*<DD>
|
|
The behavior of
|
|
<B><A HREF="/cgi-bin/man/man2html?3+malloc">malloc</A></B>(3)
|
|
|
|
is influenced by
|
|
<B>MALLOC_*</B>
|
|
|
|
variables.
|
|
<DT id="16">*<DD>
|
|
The variable
|
|
<B>HOSTALIASES</B>
|
|
|
|
gives the name of a file containing aliases
|
|
to be used with
|
|
<B><A HREF="/cgi-bin/man/man2html?3+gethostbyname">gethostbyname</A></B>(3).
|
|
|
|
<DT id="17">*<DD>
|
|
<B>TZ</B> and <B>TZDIR</B>
|
|
|
|
give timezone information used by
|
|
<B><A HREF="/cgi-bin/man/man2html?3+tzset">tzset</A></B>(3)
|
|
|
|
and through that by functions like
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ctime">ctime</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+localtime">localtime</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mktime">mktime</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3).
|
|
|
|
See also
|
|
<B><A HREF="/cgi-bin/man/man2html?8+tzselect">tzselect</A></B>(8).
|
|
|
|
<DT id="18">*<DD>
|
|
<B>TERMCAP</B>
|
|
|
|
gives information on how to address a given terminal
|
|
(or gives the name of a file containing such information).
|
|
<DT id="19">*<DD>
|
|
<B>COLUMNS</B> and <B>LINES</B>
|
|
|
|
tell applications about the window size, possibly overriding the actual size.
|
|
<DT id="20">*<DD>
|
|
<B>PRINTER</B> or <B>LPDEST</B>
|
|
|
|
may specify the desired printer to use.
|
|
See
|
|
<B><A HREF="/cgi-bin/man/man2html?1+lpr">lpr</A></B>(1).
|
|
|
|
</DL>
|
|
<A NAME="lbAE"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The
|
|
<B><A HREF="/cgi-bin/man/man2html?2+prctl">prctl</A></B>(2)
|
|
|
|
<B>PR_SET_MM_ENV_START</B>
|
|
|
|
and
|
|
<B>PR_SET_MM_ENV_END</B>
|
|
|
|
operations can be used to control the location of the process's environment.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
Clearly there is a security risk here.
|
|
Many a system command has been
|
|
tricked into mischief by a user who specified unusual values for
|
|
<B>IFS</B> or <B>LD_LIBRARY_PATH</B>.
|
|
|
|
<P>
|
|
|
|
There is also the risk of name space pollution.
|
|
Programs like
|
|
<I>make</I>
|
|
|
|
and
|
|
<I>autoconf</I>
|
|
|
|
allow overriding of default utility names from the
|
|
environment with similarly named variables in all caps.
|
|
Thus one uses
|
|
<B>CC</B>
|
|
|
|
to select the desired C compiler (and similarly
|
|
<B>MAKE</B>,
|
|
|
|
<B>AR</B>,
|
|
|
|
<B>AS</B>,
|
|
|
|
<B>FC</B>,
|
|
|
|
<B>LD</B>,
|
|
|
|
<B>LEX</B>,
|
|
|
|
<B>RM</B>,
|
|
|
|
<B>YACC</B>,
|
|
|
|
etc.).
|
|
However, in some traditional uses such an environment variable
|
|
gives options for the program instead of a pathname.
|
|
Thus, one has
|
|
<B>MORE</B>,
|
|
|
|
<B>LESS</B>,
|
|
|
|
and
|
|
<B>GZIP</B>.
|
|
|
|
Such usage is considered mistaken, and to be avoided in new
|
|
programs.
|
|
The authors of
|
|
<I>gzip</I>
|
|
|
|
should consider renaming their option to
|
|
<B>GZIP_OPT</B>.
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+bash">bash</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+csh">csh</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+env">env</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+login">login</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+printenv">printenv</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+sh">sh</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+tcsh">tcsh</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+execve">execve</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+clearenv">clearenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+exec">exec</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getenv">getenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+putenv">putenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setenv">setenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+unsetenv">unsetenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+locale">locale</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+ld.so">ld.so</A></B>(8),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+pam_env">pam_env</A></B>(8)
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="21"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="22"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="23"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="24"><A HREF="#lbAE">NOTES</A><DD>
|
|
<DT id="25"><A HREF="#lbAF">BUGS</A><DD>
|
|
<DT id="26"><A HREF="#lbAG">SEE ALSO</A><DD>
|
|
<DT id="27"><A HREF="#lbAH">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:06:08 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|