1EXPORT(1P)                 POSIX Programmer's Manual                EXPORT(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       export — set the export attribute for variables
13

SYNOPSIS

15       export name[=word]...
16
17       export -p
18

DESCRIPTION

20       The shell shall give the export attribute to the variables  correspond‐
21       ing  to  the specified names, which shall cause them to be in the envi‐
22       ronment of subsequently executed commands. If the name of a variable is
23       followed  by  =word,  then  the  value of that variable shall be set to
24       word.
25
26       The export special built-in shall support the Base  Definitions  volume
27       of POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
28
29       When  -p  is  specified,  export shall write to the standard output the
30       names and values of all exported variables, in the following format:
31
32
33           "export %s=%s\n", <name>, <value>
34
35       if name is set, and:
36
37
38           "export %s\n", <name>
39
40       if name is unset.
41
42       The shell shall format the output, including the proper use of quoting,
43       so  that  it  is  suitable  for  reinput  to the shell as commands that
44       achieve the same exporting results, except:
45
46        1. Read-only variables with values cannot be reset.
47
48        2. Variables that were unset at the time they were output need not  be
49           reset  to  the  unset  state if a value is assigned to the variable
50           between the time the state was saved and  the  time  at  which  the
51           saved output is reinput to the shell.
52
53       When no arguments are given, the results are unspecified.
54

OPTIONS

56       See the DESCRIPTION.
57

OPERANDS

59       See the DESCRIPTION.
60

STDIN

62       Not used.
63

INPUT FILES

65       None.
66

ENVIRONMENT VARIABLES

68       None.
69

ASYNCHRONOUS EVENTS

71       Default.
72

STDOUT

74       See the DESCRIPTION.
75

STDERR S

77       The standard error shall be used only for diagnostic messages.
78

OUTPUT FILES

80       None.
81

EXTENDED DESCRIPTION

83       None.
84

EXIT STATUS

86        0    All name operands were successfully exported.
87
88       >0    At  least  one  name  could not be exported, or the -p option was
89             specified and an error occurred.
90

CONSEQUENCES OF ERRORS

92       Default.
93
94       The following sections are informative.
95

APPLICATION USAGE

97       Note that, unless X was previously marked readonly, the value  of  "$?"
98       after:
99
100
101           export X=$(false)
102
103       will  be  0 (because export successfully set X to the empty string) and
104       that execution continues, even if set -e is  in  effect.  In  order  to
105       detect  command substitution failures, a user must separate the assign‐
106       ment from the export, as in:
107
108
109           X=$(false)
110           export X
111

EXAMPLES

113       Export PWD and HOME variables:
114
115
116           export PWD HOME
117
118       Set and export the PATH variable:
119
120
121           export PATH=/local/bin:$PATH
122
123       Save and restore all exported variables:
124
125
126           export -p > temp-file
127           unset a lot of variables
128           ... processing
129           . temp-file
130

RATIONALE

132       Some historical shells use  the  no-argument  case  as  the  functional
133       equivalent  of  what  is  required here with -p.  This feature was left
134       unspecified because it is not historical practice in  all  shells,  and
135       some scripts may rely on the now-unspecified results on their implemen‐
136       tations. Attempts to specify the -p output as  the  default  case  were
137       unsuccessful  in achieving consensus.  The -p option was added to allow
138       portable access to the values that can be saved and then later restored
139       using; for example, a dot script.
140

FUTURE DIRECTIONS

142       None.
143

SEE ALSO

145       Section 2.14, Special Built-In Utilities
146
147       The Base Definitions volume of POSIX.1‐2017, Section 12.2, Utility Syn‐
148       tax Guidelines
149
151       Portions of this text are reprinted and reproduced in  electronic  form
152       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
153       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
154       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
155       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
156       event of any discrepancy between this version and the original IEEE and
157       The Open Group Standard, the original IEEE and The Open Group  Standard
158       is  the  referee document. The original Standard can be obtained online
159       at http://www.opengroup.org/unix/online.html .
160
161       Any typographical or formatting errors that appear  in  this  page  are
162       most likely to have been introduced during the conversion of the source
163       files to man page format. To report such errors,  see  https://www.ker
164       nel.org/doc/man-pages/reporting_bugs.html .
165
166
167
168IEEE/The Open Group                  2017                           EXPORT(1P)
Impressum