environ(7)
โจ NAME โจ
environ โ the user environment, bestie ๐
๐ SYNOPSIS ๐
extern char **environ;
๐ธ DESCRIPTION ๐ธ
okay so. environ is a variable that points to an array of pointers to strings, and that whole thing is what we call the "environment". ๐ซ The last pointer in this array has the value NULL. This array of strings gets handed to your process by the execve(2) call when a new program starts up. And when a child process is created via fork(2), it literally inherits a copy of its parent's environment. heirloom behavior, we love to see it ๐ซถ
By convention, the strings in environ have the form "name=value". The name is case-sensitive and may not contain the character "=". The value can be literally anything that can be represented as a string. But neither the name nor the value may contain an embedded null byte ('\0'), because that byte is assumed to terminate the string. so no sneaking nulls in there, she's done ๐ญ
Environment variables can be placed in the shell's environment with the export command in sh(1), or with the setenv command if you're on csh(1).
The initial environment of the shell gets populated in all sorts of ways, like definitions from /etc/environment that are processed by pam_env(8) for all users at login time (on systems that employ pam(8)). Plus, various shell initialization scripts โ like the system-wide /etc/profile script and per-user initialization scripts โ may include commands that add variables to the shell's environment. check the manual page of whatever shell you like best for the deets ๐
Bourne-style shells support this syntax:
NAME=value command
which creates an environment variable definition only in the scope of the process that executes command. And you can stack them: multiple variable definitions, separated by white space, may precede command. slay ๐
Arguments may also be placed in the environment at the point of an exec(3). A C program can manipulate its environment using the functions getenv(3), putenv(3), setenv(3), and unsetenv(3).
What follows is a list of environment variables you'll typically see on a system. Heads up: this list is incomplete, and it only includes the common variables that average users run into in their day-to-day routine. Environment variables specific to a particular program or library function are documented in the ENVIRONMENT section of that program's own manual page. iykyk โญ
USERโ the name of the logged-in user (used by some BSD-derived programs). Set at login time; see the NOTES section below. ๐LOGNAMEโ the name of the logged-in user (used by some System-V derived programs). Set at login time; see the NOTES section below.HOMEโ a user's login directory. Set at login time; see the NOTES section below. ๐LANGโ the name of a locale to use for locale categories when it's not overridden byLC_ALLor by more specific environment variables such asLC_COLLATE,LC_CTYPE,LC_MESSAGES,LC_MONETARY,LC_NUMERIC, andLC_TIME(seelocale(7)for further details of theLC_*environment variables).PATHโ the sequence of directory prefixes thatsh(1)and many other programs use when searching for an executable file that's specified as a simple filename (i.a., a pathname that contains no slashes). The prefixes are separated by colons (:). The list of prefixes is searched from beginning to end, checking the pathname formed by catenating a prefix, a slash, and the filename, until a file with execute permission is found. ๐
As a legacy feature, a zero-length prefix (specified as two adjacent colons, or an initial or terminating colon) is interpreted to mean the current working directory. However, use of this feature is deprecated, and POSIX notes that a conforming application shall use an explicit pathname (e.g., .) to specify the current working directory.
deprecated no cap, don't do the bare-colon thing in new stuff ๐
Analogously to PATH, one has CDPATH, used by some shells to find the target of a change directory command, MANPATH used by man(1) to find manual pages, and so on.
PWDโ absolute path to the current working directory; required to be partially canonical (no.or..components). ๐SHELLโ the absolute pathname of the user's login shell. Set at login time, see the NOTES section below.TERMโ the terminal type for which output is to be prepared. ๐ฅ๏ธPAGERโ the user's preferred utility to display text files. Any string acceptable as a command-string operand to thesh -ccommand shall be valid. IfPAGERis null or is not set, then applications that launch a pager will default to a program such asless(1)ormore(1).EDITOR/VISUALโ the user's preferred utility to edit text files. Any string acceptable as acommand_stringoperand to thesh -ccommand shall be valid. โ๏ธ
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:
- The variables
LANG,LANGUAGE,NLSPATH,LOCPATH,LC_ALL,LC_MESSAGES, and so on influence locale handling; seecatopen(3),gettext(3), andlocale(7). ๐ TMPDIRinfluences the path prefix of names created bytempnam(3)and other routines, and the temporary directory used bysort(1)and other programs.LD_LIBRARY_PATH,LD_PRELOAD, and otherLD_*variables influence the behavior of the dynamic loader/linker. See alsold.so(8). ๐ฅPOSIXLY_CORRECTmakes certain programs and library routines follow the prescriptions of POSIX. periodt.- The behavior of
malloc(3)is influenced byMALLOC_*variables. - The variable
HOSTALIASESgives the name of a file containing aliases to be used withgethostbyname(3). TZandTZDIRgive timezone information used bytzset(3)and through that by functions likectime(3),localtime(3),mktime(3),strftime(3). See alsotzselect(8). โฐTERMCAPgives information on how to address a given terminal (or gives the name of a file containing such information).COLUMNSandLINEStell applications about the window size, possibly overriding the actual size.PRINTERorLPDESTmay specify the desired printer to use. Seelpr(1). ๐จ๏ธ
๐ NOTES ๐
Historically and by standard, environ must be declared in the user program. However, as a (nonstandard) programmer convenience, environ is declared in the header file <unistd.h> if the _GNU_SOURCE feature test macro is defined (see feature_test_macros(7)). cute little bonus, not standard tho ๐
The prctl(2) PR_SET_MM_ENV_START and PR_SET_MM_ENV_END operations can be used to control the location of the process's environment. ๐ง
The HOME, LOGNAME, SHELL, and USER variables are set when the user is changed via a session management interface, typically by a program such as login(1) from a user database (such as passwd(5)). (Switching to the root user using su(1) may result in a mixed environment where LOGNAME and USER are retained from the old user; see the su(1) manual page.) ๐ญ iconic chaotic behavior honestly
๐ BUGS ๐
Clearly there is a security risk here. Many a system command has been tricked into mischief by a user who specified unusual values for IFS or LD_LIBRARY_PATH. be careful bestie, that's not a vibe. ๐จ
There is also the risk of name space pollution. Programs like make and autoconf allow overriding of default utility names from the environment with similarly named variables in all caps. Thus one uses CC to select the desired C compiler (and similarly MAKE, AR, AS, FC, LD, LEX, RM, YACC, etc.). However, in some traditional uses, such an environment variable gives options for the program instead of a pathname. Thus, one has MORE and LESS. Such usage is considered mistaken, and to be avoided in new programs. don't do it, it's giving 1985 ๐ซ
๐ฆ SEE ALSO ๐ฆ
bash(1), csh(1), env(1), login(1), printenv(1), sh(1), su(1), tcsh(1), execve(2), clearenv(3), exec(3), getenv(3), putenv(3), setenv(3), unsetenv(3), locale(7), ld.so(8), pam_env(8)
and that's the whole page, bestie ๐ this one's from Linux man-pages 6.20, dated 2026-02-08 โ go forth and export responsibly, mwah ๐โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: GPL-2.0-or-later
- Copyright 1997, Andries E. Brouwer <aeb@cwi.nl>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms