Blame man7/environ.7

Packit 7cfc04
.\" Copyright (c) 1993 Michael Haardt (michael@moria.de),
Packit 7cfc04
.\"   Fri Apr  2 11:32:09 MET DST 1993
Packit 7cfc04
.\" and Andries Brouwer (aeb@cwi.nl), Fri Feb 14 21:47:50 1997.
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
Packit 7cfc04
.\" This is free documentation; you can redistribute it and/or
Packit 7cfc04
.\" modify it under the terms of the GNU General Public License as
Packit 7cfc04
.\" published by the Free Software Foundation; either version 2 of
Packit 7cfc04
.\" the License, or (at your option) any later version.
Packit 7cfc04
.\"
Packit 7cfc04
.\" The GNU General Public License's references to "object code"
Packit 7cfc04
.\" and "executables" are to be interpreted as the output of any
Packit 7cfc04
.\" document formatting or typesetting system, including
Packit 7cfc04
.\" intermediate and printed output.
Packit 7cfc04
.\"
Packit 7cfc04
.\" This manual is distributed in the hope that it will be useful,
Packit 7cfc04
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 7cfc04
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 7cfc04
.\" GNU General Public License for more details.
Packit 7cfc04
.\"
Packit 7cfc04
.\" You should have received a copy of the GNU General Public
Packit 7cfc04
.\" License along with this manual; if not, see
Packit 7cfc04
.\" <http://www.gnu.org/licenses/>.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified Sun Jul 25 10:45:30 1993 by Rik Faith (faith@cs.unc.edu)
Packit 7cfc04
.\" Modified Sun Jul 21 21:25:26 1996 by Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\" Modified Mon Oct 21 17:47:19 1996 by Eric S. Raymond (esr@thyrsus.com)
Packit 7cfc04
.\" Modified Wed Aug 27 20:28:58 1997 by Nicolás Lichtmaier (nick@debian.org)
Packit 7cfc04
.\" Modified Mon Sep 21 00:00:26 1998 by Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\" Modified Wed Jan 24 06:37:24 2001 by Eric S. Raymond (esr@thyrsus.com)
Packit 7cfc04
.\" Modified Thu Dec 13 23:53:27 2001 by Martin Schulze <joey@infodrom.org>
Packit 7cfc04
.\"
Packit 7cfc04
.TH ENVIRON 7 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
environ \- user environment
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.BI "extern char **" environ ;
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The variable
Packit 7cfc04
.I environ
Packit 7cfc04
points to an array of pointers to strings called the "environment".
Packit 7cfc04
The last pointer in this array has the value NULL.
Packit 7cfc04
(This variable must be declared in the user program,
Packit 7cfc04
but is declared in the header file
Packit 7cfc04
.I <unistd.h>
Packit 7cfc04
if the
Packit 7cfc04
.B _GNU_SOURCE
Packit 7cfc04
feature test macro is defined.)
Packit 7cfc04
This array of strings is made available to the process by the
Packit 7cfc04
.BR exec (3)
Packit 7cfc04
call that started the process.
Packit 7cfc04
When a child process is created via
Packit 7cfc04
.BR fork (2),
Packit 7cfc04
it inherits a
Packit 7cfc04
.I copy
Packit 7cfc04
of its parent's environment.
Packit 7cfc04
.PP
Packit 7cfc04
By convention the strings in
Packit 7cfc04
.I environ
Packit 7cfc04
have the form "\fIname\fP\fB=\fP\fIvalue\fP".
Packit 7cfc04
Common examples are:
Packit 7cfc04
.TP
Packit 7cfc04
.B USER
Packit 7cfc04
The name of the logged-in user (used by some BSD-derived programs).
Packit 7cfc04
.TP
Packit 7cfc04
.B LOGNAME
Packit 7cfc04
The name of the logged-in user (used by some System-V derived programs).
Packit 7cfc04
.TP
Packit 7cfc04
.B HOME
Packit 7cfc04
A user's login directory, set by
Packit 7cfc04
.BR login (1)
Packit 7cfc04
from the password file
Packit 7cfc04
.BR passwd (5).
Packit 7cfc04
.TP
Packit 7cfc04
.B LANG
Packit 7cfc04
The name of a locale to use for locale categories when not overridden
Packit 7cfc04
by
Packit 7cfc04
.B LC_ALL
Packit 7cfc04
or more specific environment variables such as
Packit 7cfc04
.BR LC_COLLATE ,
Packit 7cfc04
.BR LC_CTYPE ,
Packit 7cfc04
.BR LC_MESSAGES ,
Packit 7cfc04
.BR LC_MONETARY ,
Packit 7cfc04
.BR LC_NUMERIC ,
Packit 7cfc04
and
Packit 7cfc04
.BR LC_TIME
Packit 7cfc04
(see
Packit 7cfc04
.BR locale (7)
Packit 7cfc04
for further details of the
Packit 7cfc04
.BR LC_*
Packit 7cfc04
environment variables).
Packit 7cfc04
.TP
Packit 7cfc04
.B PATH
Packit 7cfc04
The sequence of directory prefixes that
Packit 7cfc04
.BR sh (1)
Packit 7cfc04
and many other
Packit 7cfc04
programs apply in searching for a file known by an incomplete pathname.
Packit 7cfc04
The prefixes are separated by \(aq\fB:\fP\(aq.
Packit 7cfc04
(Similarly one has
Packit 7cfc04
.B CDPATH
Packit 7cfc04
used by some shells to find the target
Packit 7cfc04
of a change directory command,
Packit 7cfc04
.B MANPATH
Packit 7cfc04
used by
Packit 7cfc04
.BR man (1)
Packit 7cfc04
to find manual pages, and so on)
Packit 7cfc04
.TP
Packit 7cfc04
.B PWD
Packit 7cfc04
The current working directory.
Packit 7cfc04
Set by some shells.
Packit 7cfc04
.TP
Packit 7cfc04
.B SHELL
Packit 7cfc04
The pathname of the user's login shell.
Packit 7cfc04
.TP
Packit 7cfc04
.B TERM
Packit 7cfc04
The terminal type for which output is to be prepared.
Packit 7cfc04
.TP
Packit 7cfc04
.B PAGER
Packit 7cfc04
The user's preferred utility to display text files.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EDITOR / VISUAL
Packit 7cfc04
The user's preferred utility to edit text files.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .B BROWSER
Packit 7cfc04
.\" The user's preferred utility to browse URLs. Sequence of colon-separated
Packit 7cfc04
.\" browser commands. See http://www.catb.org/~esr/BROWSER/ .
Packit 7cfc04
.PP
Packit 7cfc04
Names may be placed in the shell's environment by the
Packit 7cfc04
.I export
Packit 7cfc04
command in
Packit 7cfc04
.BR sh (1),
Packit 7cfc04
or by the
Packit 7cfc04
.I setenv
Packit 7cfc04
command if you use
Packit 7cfc04
.BR csh (1).
Packit 7cfc04
.PP
Packit 7cfc04
The initial environment of the shell is populated in various ways,
Packit 7cfc04
such as definitions from
Packit 7cfc04
.IR /etc/environment
Packit 7cfc04
that are processed by
Packit 7cfc04
.BR pam_env (8)
Packit 7cfc04
for all users at login time (on systems that employ
Packit 7cfc04
.BR pam (8)).
Packit 7cfc04
In addition, various shell initialization scripts, such as the system-wide
Packit 7cfc04
.IR /etc/profile
Packit 7cfc04
script and per-user initializations script may include commands
Packit 7cfc04
that add variables to the shell's environment;
Packit 7cfc04
see the manual page of your preferred shell for details.
Packit 7cfc04
.PP
Packit 7cfc04
Bourne-style shells support the syntax
Packit 7cfc04
.PP
Packit 7cfc04
    NAME=value command
Packit 7cfc04
.PP
Packit 7cfc04
to create an environment variable definition only in the scope
Packit 7cfc04
of the process that executes
Packit 7cfc04
.IR command .
Packit 7cfc04
Multiple variable definitions, separated by white space, may precede
Packit 7cfc04
.IR command .
Packit 7cfc04
.PP
Packit 7cfc04
Arguments may also be placed in the
Packit 7cfc04
environment at the point of an
Packit 7cfc04
.BR exec (3).
Packit 7cfc04
A C program can manipulate its environment using the functions
Packit 7cfc04
.BR getenv (3),
Packit 7cfc04
.BR putenv (3),
Packit 7cfc04
.BR setenv (3),
Packit 7cfc04
and
Packit 7cfc04
.BR unsetenv (3).
Packit 7cfc04
.PP
Packit 7cfc04
Note that the behavior of many programs and library routines is
Packit 7cfc04
influenced by the presence or value of certain environment variables.
Packit 7cfc04
Examples include the following:
Packit 7cfc04
.IP * 3
Packit 7cfc04
The variables
Packit 7cfc04
.BR LANG ", " LANGUAGE ", " NLSPATH ", " LOCPATH ", "
Packit 7cfc04
.BR LC_ALL ", " LC_MESSAGES ", "
Packit 7cfc04
and so on influence locale handling; see
Packit 7cfc04
.BR catopen (3),
Packit 7cfc04
.BR gettext (3),
Packit 7cfc04
and
Packit 7cfc04
.BR locale (7).
Packit 7cfc04
.IP *
Packit 7cfc04
.B TMPDIR
Packit 7cfc04
influences the path prefix of names created by
Packit 7cfc04
.BR tempnam (3)
Packit 7cfc04
and other routines, and the temporary directory used by
Packit 7cfc04
.BR sort (1)
Packit 7cfc04
and other programs.
Packit 7cfc04
.IP *
Packit 7cfc04
.BR LD_LIBRARY_PATH ", " LD_PRELOAD ,
Packit 7cfc04
and other
Packit 7cfc04
.BR LD_*
Packit 7cfc04
variables influence the behavior of the dynamic loader/linker.
Packit 7cfc04
.IP *
Packit 7cfc04
.B POSIXLY_CORRECT
Packit 7cfc04
makes certain programs and library routines follow
Packit 7cfc04
the prescriptions of POSIX.
Packit 7cfc04
.IP *
Packit 7cfc04
The behavior of
Packit 7cfc04
.BR malloc (3)
Packit 7cfc04
is influenced by
Packit 7cfc04
.B MALLOC_*
Packit 7cfc04
variables.
Packit 7cfc04
.IP *
Packit 7cfc04
The variable
Packit 7cfc04
.B HOSTALIASES
Packit 7cfc04
gives the name of a file containing aliases
Packit 7cfc04
to be used with
Packit 7cfc04
.BR gethostbyname (3).
Packit 7cfc04
.IP *
Packit 7cfc04
.BR TZ " and " TZDIR
Packit 7cfc04
give timezone information used by
Packit 7cfc04
.BR tzset (3)
Packit 7cfc04
and through that by functions like
Packit 7cfc04
.BR ctime (3),
Packit 7cfc04
.BR localtime (3),
Packit 7cfc04
.BR mktime (3),
Packit 7cfc04
.BR strftime (3).
Packit 7cfc04
See also
Packit 7cfc04
.BR tzselect (8).
Packit 7cfc04
.IP *
Packit 7cfc04
.B TERMCAP
Packit 7cfc04
gives information on how to address a given terminal
Packit 7cfc04
(or gives the name of a file containing such information).
Packit 7cfc04
.IP *
Packit 7cfc04
.BR COLUMNS " and " LINES
Packit 7cfc04
tell applications about the window size, possibly overriding the actual size.
Packit 7cfc04
.IP *
Packit 7cfc04
.BR PRINTER " or " LPDEST
Packit 7cfc04
may specify the desired printer to use.
Packit 7cfc04
See
Packit 7cfc04
.BR lpr (1).
Packit 7cfc04
.SH NOTES
Packit 7cfc04
The
Packit 7cfc04
.BR prctl (2)
Packit 7cfc04
.B PR_SET_MM_ENV_START
Packit 7cfc04
and
Packit 7cfc04
.B PR_SET_MM_ENV_END
Packit 7cfc04
operations can be used to control the location of the process's environment.
Packit 7cfc04
.SH BUGS
Packit 7cfc04
Clearly there is a security risk here.
Packit 7cfc04
Many a system command has been
Packit 7cfc04
tricked into mischief by a user who specified unusual values for
Packit 7cfc04
.BR IFS " or " LD_LIBRARY_PATH .
Packit 7cfc04
.PP
Packit 7cfc04
There is also the risk of name space pollution.
Packit 7cfc04
Programs like
Packit 7cfc04
.I make
Packit 7cfc04
and
Packit 7cfc04
.I autoconf
Packit 7cfc04
allow overriding of default utility names from the
Packit 7cfc04
environment with similarly named variables in all caps.
Packit 7cfc04
Thus one uses
Packit 7cfc04
.B CC
Packit 7cfc04
to select the desired C compiler (and similarly
Packit 7cfc04
.BR MAKE ,
Packit 7cfc04
.BR AR ,
Packit 7cfc04
.BR AS ,
Packit 7cfc04
.BR FC ,
Packit 7cfc04
.BR LD ,
Packit 7cfc04
.BR LEX ,
Packit 7cfc04
.BR RM ,
Packit 7cfc04
.BR YACC ,
Packit 7cfc04
etc.).
Packit 7cfc04
However, in some traditional uses such an environment variable
Packit 7cfc04
gives options for the program instead of a pathname.
Packit 7cfc04
Thus, one has
Packit 7cfc04
.BR MORE ,
Packit 7cfc04
.BR LESS ,
Packit 7cfc04
and
Packit 7cfc04
.BR GZIP .
Packit 7cfc04
Such usage is considered mistaken, and to be avoided in new
Packit 7cfc04
programs.
Packit 7cfc04
The authors of
Packit 7cfc04
.I gzip
Packit 7cfc04
should consider renaming their option to
Packit 7cfc04
.BR GZIP_OPT .
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR bash (1),
Packit 7cfc04
.BR csh (1),
Packit 7cfc04
.BR env (1),
Packit 7cfc04
.BR login (1),
Packit 7cfc04
.BR printenv (1),
Packit 7cfc04
.BR sh (1),
Packit 7cfc04
.BR tcsh (1),
Packit 7cfc04
.BR execve (2),
Packit 7cfc04
.BR clearenv (3),
Packit 7cfc04
.BR exec (3),
Packit 7cfc04
.BR getenv (3),
Packit 7cfc04
.BR putenv (3),
Packit 7cfc04
.BR setenv (3),
Packit 7cfc04
.BR unsetenv (3),
Packit 7cfc04
.BR locale (7),
Packit 7cfc04
.BR ld.so (8),
Packit 7cfc04
.BR pam_env (8)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.