1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// This file is part of yash, an extended POSIX shell.
// Copyright (C) 2023 WATANABE Yuki
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Export built-in
//!
//! The **`export`** built-in exports shell variables to the environment.
//!
//! # Synopsis
//!
//! ```sh
//! 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.
//!
//! (TODO: Other non-portable options)
//!
//! # Operands
//!
//! The operands are the names of shell 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.
//!
//! # Exit status
//!
//! Zero unless an error occurs.
//!
//! # Portability
//!
//! This built-in is part of the POSIX standard. Printing variables is portable
//! only when the `-p` option is used without operands.
//!
//! # Implementation notes
//!
//! The implementation of this built-in depends on that of the
//! [`typeset`](crate::typeset) built-in. The export built-in basically works
//! like the typeset built-in with the `-gx` (`--global --export`) options,
//! except that:
//! - Printed commands name the export built-in instead of the typeset built-in.
//! - Printed commands do not include options that modify variable attributes.
use crateoutput;
use cratereport_error;
use cratereport_failure;
use crateto_single_message;
use crateinterpret;
use crateparse;
use crateOptionSpec;
use cratePRINT_OPTION;
use crateCommand;
use cratePrintContext;
use crateGlobal;
use crateExport;
use On;
use Field;
use Env;
/// List of portable options applicable to the export built-in
pub const PORTABLE_OPTIONS: & = &;
/// Printing context for the export built-in
pub const PRINT_CONTEXT: = PrintContext ;
/// Entry point of the export built-in
pub async