Export built-in
The export built-in exports variables to the environment.
Synopsis
export [-p] [NAME[=VALUE]…]
Description
The export built-in (without the -p option) exports variables of the specified names to the environment, with optional values. If no names are given, or if the -p option is given, the names and values of all exported variables are displayed. If the -p option is given with operands, only the specified variables are displayed.
Options
The -p (--print) option causes the shell to display the names and
values of all exported variables in a format that can be reused as input to
restore the state of these variables. When used with operands, the option
limits the output to the specified variables.
(Since 3.6.0) The --help option prints the help of the built-in.
Operands
The operands are the names of variables to be exported or printed. When exporting, each name may optionally be followed by = and a value to assign to the variable.
Standard output
When exporting variables, the export built-in does not produce any output.
When printing variables, the built-in prints simple commands that invoke the export built-in to reexport the variables with the same values. Note that the commands do not include options to restore the attributes of the variables, such as the -r option to make variables read-only.
For array variables, the export built-in invocation is preceded by a separate assignment command since the export built-in does not support assigning values to array variables.
Errors
When exporting a variable with a value, it is an error if the variable is read-only.
When printing variables, it is an error if an operand names a non-existing variable.
The portable option causes additional errors; see Compatibility.
Exit status
Zero unless an error occurs.
Examples
Compatibility
This built-in is part of the POSIX standard. Printing variables is portable
only when the -p option is used without operands. The long option name
--print and the --help option are non-standard extensions.
When the portable option is set, these are errors:
- (Since 3.3.3) Exporting a variable whose name contains a character other than ASCII letters, digits, and underscores, or starts with a digit.
- (Since 3.3.5) Invoking the built-in without operands and without the
-poption, or with the-poption and one or more operands. POSIX specifies only theexport NAME…andexport -pforms. - (Since 3.3.5) Using the
--printoption, spelled out in full or abbreviated. Use-pinstead.
Previous versions of yash supported the non-standard -r and -X options, but these are not yet supported in yash-rs.