EXPORT(1POSIX)
๐ EXPORT โ set the export attribute for variables ๐
okay bestie, welcome to EXPORT(1POSIX) from the POSIX Programmer's Manual โจ this is the page for the export special built-in, and it's lowkey one of the most important shell things you'll ever touch, no cap ๐ซถ
๐จ PROLOG ๐จ
Real talk first, because this part matters: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the details of Linux behavior), or honestly the interface may not be implemented on Linux at all. It's giving "results may vary" ๐
๐ธ NAME ๐ธ
export โ set the export attribute for variables. that's the whole vibe. one job. iconic.
โจ SYNOPSIS โจ
export name[=word]...
export -p
two moods, one built-in ๐
๐ DESCRIPTION ๐
So here's the tea, bestie ๐ต the shell shall give the export attribute to the variables corresponding to the specified names, which shall cause them to be in the environment of subsequently executed commands. Basically you're telling the shell "hey, pass this along to everything I run next" and it's like "say less" ๐ฅ
If the name of a variable is followed by =word, then the value of that variable shall be set to word. so you can do both at once, queen behavior ๐
The export special built-in shall support the Base Definitions volume of POSIX.1โ2017, Section 12.2, Utility Syntax Guidelines. yes, that's a real citation, we're being thorough, we contain multitudes ๐
When -p is specified, export shall write to the standard output the names and values of all exported variables, in the following format:
"export %s=%s\n", <name>, <value>
if name is set, and:
"export %s\n", <name>
if name is unset. so basically it dumps everything back out in a form you could feed right back in, which is honestly so convenient, main character energy โญ
The shell shall format the output, including the proper use of quoting, so that it is suitable for reinput to the shell as commands that achieve the same exporting results, except โ and listen, there are two exceptions, don't skip them:
- Read-only variables with values cannot be reset. nope. not happening. read-only means read-only ๐
- Variables that were unset at the time they were output need not be reset to the unset state if a value is assigned to the variable between the time the state was saved and the time at which the saved output is reinput to the shell. (i.e. if you snoop around and set it in the middle, the restore isn't obligated to un-set it. it's giving "you did this to yourself" ๐)
When no arguments are given, the results are unspecified. unspecified!! which is a fancy way of saying "we're not telling you what happens, don't rely on it" ๐ญ
๐ OPTIONS ๐
See the DESCRIPTION. yeah, the -p is up there, we covered it, go look ๐
๐ฆ OPERANDS ๐ฆ
See the DESCRIPTION. also up there. the name[=word]... situation. you got this ๐
๐ STDIN ๐
Not used. it's not even invited to the party.
๐ซ INPUT FILES ๐ซ
None. nothing to see here.
๐ธ ENVIRONMENT VARIABLES ๐ธ
None. the irony of the environment-variables page having no environment variables is not lost on us, bestie ๐ญ
โก ASYNCHRONOUS EVENTS โก
Default. standard behavior, no drama.
๐ซถ STDOUT ๐ซถ
See the DESCRIPTION. (it's the -p output, the "export %s=%s\n" format, that whole gorgeous thing โจ)
๐ STDERR S ๐
The standard error shall be used only for diagnostic messages. so if it's yelling at you, that's a real message, pay attention ๐จ
๐ OUTPUT FILES ๐
None.
๐ง EXTENDED DESCRIPTION ๐ง
None. there is no extended description. we said what we said ๐
๐ EXIT STATUS ๐
0โ All name operands were successfully exported. slay ๐>0โ At least one name could not be exported, or the-poption was specified and an error occurred. it's giving "we have a problem" ๐ญ
๐ CONSEQUENCES OF ERRORS ๐
Default.
The following sections are informative. (so like, vibe-wise they're context, not law, iykyk)
๐ฅ APPLICATION USAGE ๐ฅ
okay this one is genuinely important, listen up bestie ๐ข
Note that, unless X was previously marked readonly, the value of "$?" after:
export X=$(false)
will be 0 (because export successfully set X to the empty string) and that execution continues, even if set -e is in effect. so like โ the command substitution failed, but export itself succeeded, so $? is happy and set -e doesn't trip. sneaky, right?? ๐
In order to detect command substitution failures, a user must separate the assignment from the export, as in:
X=$(false)
export X
periodt. do it in two steps if you actually want to catch the failure ๐
๐ EXAMPLES ๐
Export PWD and HOME variables:
export PWD HOME
Set and export the PATH variable:
export PATH=/local/bin:$PATH
Save and restore all exported variables:
export -p > temp-file
unset a lot of variables
... processing
. temp-file
the save-and-restore one is chef's kiss, it's literally a little snapshot of your shell environment ๐โจ
๐ง RATIONALE ๐ง
Some historical shells use the no-argument case as the functional equivalent of what is required here with -p. This feature was left unspecified because it is not historical practice in all shells, and some scripts may rely on the now-unspecified results on their implementations. Attempts to specify the -p output as the default case were unsuccessful in achieving consensus. The -p option was added to allow portable access to the values that can be saved and then later restored using; for example, a dot script.
so yeah, the reason no-args is unspecified is literally "we could not all agree" ๐ committee vibes, but make it POSIX.
๐ฎ FUTURE DIRECTIONS ๐ฎ
None. the future is now, and it looks exactly like the present ๐
๐ SEE ALSO ๐
- Section 2.14, Special Built-In Utilities
- The Base Definitions volume of POSIX.1โ2017, Section 12.2, Utility Syntax Guidelines
๐ COPYRIGHT ๐
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie ๐ซถ brought to you by IEEE/The Open Group, 2017 โ thanks for reading, now go export something and make it everyone's problem ๐ โจ๐
๐ฆ where this page comes from
- debian bookworm: manpages-posix 2017a-2 ยท Other
- debian trixie: manpages-posix 2017a-2 ยท Other
- ubuntu jammy: manpages-posix 2017a-2 ยท Other
- ubuntu noble: manpages-posix 2017a-2 ยท Other
- ubuntu resolute: manpages-posix 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms