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 by LC_ALL or by more specific environment variables such as LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and LC_TIME (see locale(7) for further details of the LC_* environment variables).
  • PATH โ€” the sequence of directory prefixes that sh(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 the sh -c command shall be valid. If PAGER is null or is not set, then applications that launch a pager will default to a program such as less(1) or more(1).
  • EDITOR/VISUAL โ€” the user's preferred utility to edit text files. Any string acceptable as a command_string operand to the sh -c command 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; see catopen(3), gettext(3), and locale(7). ๐ŸŒ
  • TMPDIR influences the path prefix of names created by tempnam(3) and other routines, and the temporary directory used by sort(1) and other programs.
  • LD_LIBRARY_PATH, LD_PRELOAD, and other LD_* variables influence the behavior of the dynamic loader/linker. See also ld.so(8). ๐Ÿ”ฅ
  • POSIXLY_CORRECT makes certain programs and library routines follow the prescriptions of POSIX. periodt.
  • The behavior of malloc(3) is influenced by MALLOC_* variables.
  • The variable HOSTALIASES gives the name of a file containing aliases to be used with gethostbyname(3).
  • TZ and TZDIR give timezone information used by tzset(3) and through that by functions like ctime(3), localtime(3), mktime(3), strftime(3). See also tzselect(8). โฐ
  • TERMCAP gives information on how to address a given terminal (or gives the name of a file containing such information).
  • COLUMNS and LINES tell applications about the window size, possibly overriding the actual size.
  • PRINTER or LPDEST may specify the desired printer to use. See lpr(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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms