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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// This file is part of yash, an extended POSIX shell.
// Copyright (C) 2024 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/>.
//! Variable name and default value constants
/// The name of the `CDPATH` variable
///
/// The `CDPATH` variable is used by the `cd` built-in to search for
/// directories. Its value is a colon-separated list of directories.
pub const CDPATH: &str = "CDPATH";
/// The name of the `ENV` variable
///
/// The `ENV` variable specifies the file to read for environment
/// variables when the shell is invoked.
pub const ENV: &str = "ENV";
/// The name of the `HOME` variable
///
/// The `HOME` variable stores the path to the user's home directory.
pub const HOME: &str = "HOME";
/// The name of the `IFS` variable
///
/// The `IFS` variable separator characters for field splitting.
/// The initial value is `" \t\n"`.
pub const IFS: &str = "IFS";
/// The initial value of the `IFS` variable (`" \t\n"`)
pub const IFS_INITIAL_VALUE: &str = " \t\n";
/// The name of the `LINENO` variable
///
/// The `LINENO` variable expands to the line number of the current command.
pub const LINENO: &str = "LINENO";
/// The name of the `OLDPWD` variable
///
/// The `cd` built-in sets the `OLDPWD` variable to the previous working directory.
pub const OLDPWD: &str = "OLDPWD";
/// The name of the `OPTARG` variable
///
/// The `OPTARG` variable is used by the `getopts` built-in to store the
/// argument of an option.
pub const OPTARG: &str = "OPTARG";
/// The name of the `OPTIND` variable
///
/// The `OPTIND` variable is used by the `getopts` built-in to store the
/// index of the next argument to be processed. The initial value is `1`.
pub const OPTIND: &str = "OPTIND";
/// The initial value of the `OPTIND` variable (`1`)
pub const OPTIND_INITIAL_VALUE: &str = "1";
/// The name of the `PATH` variable
///
/// The `PATH` variable stores the directories to search for executables.
pub const PATH: &str = "PATH";
/// The name of the `PPID` variable
///
/// The `PPID` variable stores the process ID of the parent process.
pub const PPID: &str = "PPID";
/// The name of the `PS1` variable
///
/// The `PS1` variable is the primary prompt string.
/// The initial value depends on the user's privilege level.
/// See [`PS1_INITIAL_VALUE_NON_ROOT`] and [`PS1_INITIAL_VALUE_ROOT`].
pub const PS1: &str = "PS1";
/// The initial value of the `PS1` variable for non-root user (`"$ "`)
pub const PS1_INITIAL_VALUE_NON_ROOT: &str = "$ ";
/// The initial value of the `PS1` variable for root user (`"# "`)
pub const PS1_INITIAL_VALUE_ROOT: &str = "# ";
/// The name of the `PS2` variable
///
/// The `PS2` variable is the secondary prompt string, which is shown
/// when the shell expects more input to complete a command.
/// The initial value is `"> "`.
pub const PS2: &str = "PS2";
/// The initial value of the `PS2` variable (`"> "`)
pub const PS2_INITIAL_VALUE: &str = "> ";
/// The name of the `PS4` variable
///
/// The `PS4` variable is used by the [`XTrace`](crate::option::XTrace) option
/// to show the command before it is executed. The value is prefixed to the
/// printed command. The initial value is `"+ "`.
pub const PS4: &str = "PS4";
/// The initial value of the `PS4` variable (`"+ "`)
pub const PS4_INITIAL_VALUE: &str = "+ ";
/// The name of the `PWD` variable
///
/// The `PWD` variable stores the current working directory.
pub const PWD: &str = "PWD";
/// Tests if a string is a variable name usable in a POSIXly-portable way.
///
/// POSIX defines a _name_ as a word consisting solely of underscores, digits,
/// and alphabetics from the portable character set, the first character of
/// which is not a digit. This function returns `true` if the string is a
/// non-empty word of ASCII alphanumerics and underscores that does not start
/// with a digit.
///
/// Note that this function only checks the syntax of the name. Variables with
/// a portable name may still be non-portable to modify in a specific way; see
/// [`is_portable_readonly_variable_name`].
/// Tests if a variable may be made read-only in a POSIXly-portable way.
///
/// POSIX requires the shell to be able to update the `PWD`, `OLDPWD`,
/// `OPTIND`, `OPTARG`, and `LINENO` variables during normal operation, so
/// making any of them read-only is not portable. This function returns
/// `false` for these five variable names and `true` for any other name.