1 | ---
|
2 | title: Global Shell Options (Oils Reference)
|
3 | all_docs_url: ..
|
4 | body_css_class: width40
|
5 | default_highlighter: oils-sh
|
6 | preserve_anchor_case: yes
|
7 | ---
|
8 |
|
9 | <div class="doc-ref-header">
|
10 |
|
11 | [Oils Reference](index.html) —
|
12 | Chapter **Global Shell Options**
|
13 |
|
14 | </div>
|
15 |
|
16 | This chapter describes global shell options in Oils. Some options are from
|
17 | POSIX shell, and some are from [bash]($xref). We also use options to turn
|
18 | [OSH]($xref) into [YSH]($xref).
|
19 |
|
20 | <span class="in-progress">(in progress)</span>
|
21 |
|
22 | <div id="dense-toc">
|
23 | </div>
|
24 |
|
25 | ## Errors
|
26 |
|
27 | These options are from POSIX shell:
|
28 |
|
29 | nounset -u
|
30 | errexit -e
|
31 |
|
32 | These are from bash:
|
33 |
|
34 | inherit_errexit:
|
35 | pipefail
|
36 |
|
37 | ## Globbing
|
38 |
|
39 | These options are from POSIX shell:
|
40 |
|
41 | noglob -f
|
42 |
|
43 | From bash:
|
44 |
|
45 | nullglob failglob dotglob
|
46 |
|
47 | From Oils:
|
48 |
|
49 | dashglob
|
50 |
|
51 | Some details:
|
52 |
|
53 | ### nullglob
|
54 |
|
55 | When `nullglob` is on, a glob matching no files expands to no arguments:
|
56 |
|
57 | shopt -s nullglob
|
58 | $ echo L *.py R
|
59 | L R
|
60 |
|
61 | Without this option, the glob string itself is returned:
|
62 |
|
63 | $ echo L *.py R # no Python files in this dir
|
64 | L *.py R
|
65 |
|
66 | (This option is from GNU bash.)
|
67 |
|
68 | ### dashglob
|
69 |
|
70 | Do globs return results that start with `-`? It's on by default in `bin/osh`,
|
71 | but off when YSH is enabled.
|
72 |
|
73 | Turning it off prevents a command like `rm *` from being confused by a file
|
74 | called `-rf`.
|
75 |
|
76 | $ touch -- myfile -rf
|
77 |
|
78 | $ echo *
|
79 | -rf myfile
|
80 |
|
81 | $ shopt -u dashglob
|
82 | $ echo *
|
83 | myfile
|
84 |
|
85 | ## Debugging
|
86 |
|
87 | These options are from POSIX shell:
|
88 |
|
89 | xtrace verbose
|
90 |
|
91 | From bash:
|
92 |
|
93 | extdebug
|
94 |
|
95 | ## Interactive
|
96 |
|
97 | These options are from bash.
|
98 |
|
99 | emacs vi
|
100 |
|
101 | ## Other Option
|
102 |
|
103 | noclobber # Redirects don't overwrite files
|
104 |
|
105 | ## Compat
|
106 |
|
107 | ### eval_unsafe_arith
|
108 |
|
109 | Allow dynamically parsed `a[$(echo 42)]` For bash compatibility.
|
110 |
|
111 | ### ignore_flags_not_impl
|
112 |
|
113 | Suppress failures from flags not implemented. Example:
|
114 |
|
115 | shopt --set ignore_flags_not_impl
|
116 |
|
117 | declare -i foo=2+3 # not evaluated to 5, but doesn't fail either
|
118 |
|
119 | This option can be useful for "getting past" errors while testing.
|
120 |
|
121 | ## Groups
|
122 |
|
123 | To turn OSH into YSH, we use three option groups. Some of them allow new
|
124 | features, and some disallow old features.
|
125 |
|
126 | <!-- note: explicit anchor necessary because of mangling -->
|
127 | <h3 id="strict:all">strict:all</h3>
|
128 |
|
129 | Option in this group disallow problematic or confusing shell constructs. The
|
130 | resulting script will still run in another shell.
|
131 |
|
132 | shopt --set strict:all # turn on all options
|
133 | shopt -p strict:all # print their current state
|
134 |
|
135 | Parsing options:
|
136 |
|
137 | strict_parse_slice # No implicit length for ${a[@]::}
|
138 | X strict_parse_utf8 # Source code must be valid UTF-8
|
139 |
|
140 | Runtime options:
|
141 |
|
142 | strict_argv # No empty argv
|
143 | strict_arith # Fatal parse errors (on by default)
|
144 | strict_array # Arrays and strings aren't confused
|
145 | strict_control_flow # Disallow misplaced keyword, empty arg
|
146 | strict_errexit # Disallow code that ignores failure
|
147 | strict_nameref # Trap invalid variable names
|
148 | strict_word_eval # Expose unicode and slicing errors
|
149 | strict_tilde # Tilde subst can result in error
|
150 | X strict_glob # Parse the sublanguage more strictly
|
151 |
|
152 | <h3 id="ysh:upgrade">ysh:upgrade</h3>
|
153 |
|
154 | Options in this group enable new YSH features. It doesn't break existing shell
|
155 | scripts when it's avoidable.
|
156 |
|
157 | For example, `parse_at` means that `@myarray` is now the operation to splice
|
158 | an array. This will break scripts that expect `@` to be literal, but you can
|
159 | simply quote it like `'@literal'` to fix the problem.
|
160 |
|
161 | shopt --set ysh:upgrade # turn on all options
|
162 | shopt -p ysh:upgrade # print their current state
|
163 |
|
164 | Details on each option:
|
165 |
|
166 | parse_at echo @array @[arrayfunc(x, y)]
|
167 | parse_brace if true { ... }; cd ~/src { ... }
|
168 | parse_equals x = 'val' in Caps { } config blocks
|
169 | parse_paren if (x > 0) ...
|
170 | parse_proc proc p { ... }
|
171 | parse_triple_quote """$x""" '''x''' (command mode)
|
172 | parse_ysh_string echo r'\' u'\\' b'\\' (command mode)
|
173 | command_sub_errexit Synchronous errexit check
|
174 | process_sub_fail Analogous to pipefail for process subs
|
175 | sigpipe_status_ok status 141 -> 0 in pipelines
|
176 | simple_word_eval No splitting, static globbing
|
177 | xtrace_rich Hierarchical and process tracing
|
178 | xtrace_details (-u) Disable most tracing with +
|
179 | dashglob (-u) Disabled to avoid files like -rf
|
180 | X env_dict Copy environ into ENV dict
|
181 |
|
182 |
|
183 | <h3 id="ysh:all">ysh:all</h3>
|
184 |
|
185 | Enable the full YSH language. This includes everything in the `ysh:upgrade`
|
186 | group and the `strict:all` group.
|
187 |
|
188 | shopt --set ysh:all # turn on all options
|
189 | shopt -p ysh:all # print their current state
|
190 |
|
191 | Details on options that are not in `ysh:upgrade` and `strict:all`:
|
192 |
|
193 | parse_at_all @ starting any word is an operator
|
194 | parse_backslash (-u) Allow bad backslashes in "" and $''
|
195 | parse_backticks (-u) Allow legacy syntax `echo hi`
|
196 | parse_bare_word (-u) 'case unquoted' and 'for x in unquoted'
|
197 | parse_dollar (-u) Allow bare $ to mean \$ (maybe $/d+/)
|
198 | parse_dbracket (-u) Is legacy [[ allowed?
|
199 | parse_dparen (-u) Is (( legacy arithmetic allowed?
|
200 | parse_ignored (-u) Parse, but ignore, certain redirects
|
201 | parse_sh_arith (-u) Allow legacy shell arithmetic
|
202 | expand_aliases (-u) Whether aliases are expanded
|
203 | X no_env_vars Use $[ENV.PYTHONPATH], not $PYTHONPATH
|
204 | X old_builtins (-u) local/declare/etc. pushd/popd/dirs
|
205 | ... source unset printf [un]alias
|
206 | ... getopts
|
207 | X old_syntax (-u) ( ) ${x%prefix} ${a[@]} $$
|
208 | simple_echo echo doesn't accept flags -e -n
|
209 | simple_eval_builtin eval takes exactly 1 argument
|
210 | simple_test_builtin 3 args or fewer; use test not [
|
211 | X simple_trap Function name only
|
212 | verbose_errexit Whether to print detailed errors
|
213 |
|
214 | ## YSH Details
|
215 |
|
216 | ### opts-redefine
|
217 |
|
218 | In the interactive shell, you can redefine procs and funcs.
|
219 |
|
220 | redefine_module 'module' builtin always returns 0
|
221 | redefine_proc_func (-u) Can shell func, proc and func be redefined?
|
222 | X redefine_const Can consts be redefined?
|
223 |
|
224 | ### opts-internal
|
225 |
|
226 | These options are used by the interpreter. You generally shouldn't set them
|
227 | yourself.
|
228 |
|
229 | _allow_command_sub To implement strict_errexit, eval_unsafe_arith
|
230 | _allow_process_sub To implement strict_errexit
|
231 | dynamic_scope To implement proc and func
|
232 | _no_debug_trap Used in pipelines in job control shell
|
233 | _running_trap To disable strict_errexit
|
234 | _running_hay Hay evaluation
|
235 |
|
236 | ## Unlinked Descriptions
|
237 |
|
238 | Here are some descriptions of individual options.
|
239 |
|
240 | ### strict_control_flow
|
241 |
|
242 | Disallow `break` and `continue` at the top level, and disallow empty args like
|
243 | `return $empty`.
|
244 |
|
245 | ### strict_tilde
|
246 |
|
247 | Failed tilde expansions cause hard errors (like zsh) rather than silently
|
248 | evaluating to `~` or `~bad`.
|
249 |
|
250 |
|
251 | ### strict_nameref
|
252 |
|
253 | When `strict_nameref` is set, undefined references produce fatal errors:
|
254 |
|
255 | declare -n ref
|
256 | echo $ref # fatal error, not empty string
|
257 | ref=x # fatal error instead of decaying to non-reference
|
258 |
|
259 | References that don't contain variables also produce hard errors:
|
260 |
|
261 | declare -n ref='not a var'
|
262 | echo $ref # fatal
|
263 | ref=x # fatal
|
264 |
|
265 | ### parse_ignored
|
266 |
|
267 | For compatibility, YSH will parse some constructs it doesn't execute, like:
|
268 |
|
269 | return 0 2>&1 # redirect on control flow
|
270 |
|
271 | When this option is disabled, that statement is a syntax error.
|
272 |
|
273 | ### parse_triple_quote
|
274 |
|
275 | Parse the shell-style multi-line strings, which strip leading whitespace:
|
276 |
|
277 | echo '''
|
278 | one
|
279 | two
|
280 | '''
|
281 |
|
282 | echo """
|
283 | hello
|
284 | $name
|
285 | """
|
286 |
|
287 | (This option affects only command mode. Such strings are always parsed in
|
288 | expression mode.)
|
289 |
|
290 | ### parse_ysh_string
|
291 |
|
292 | Allow `r'\'` and `u'\\'` and `b'\\'` strings, as well as their multi-line
|
293 | versions.
|
294 |
|
295 | Since shell strings are already raw, this means that YSH just ignores the r
|
296 | prefix:
|
297 |
|
298 | echo r'\' # a single backslash
|
299 |
|
300 | J8 unicode strings:
|
301 |
|
302 | echo u'mu \u{3bc}' # mu char
|
303 |
|
304 | J8 byte strings:
|
305 |
|
306 | echo b'byte \yff'
|
307 |
|
308 | (This option affects only command mode. Such strings are always parsed in
|
309 | expression mode.)
|
310 |
|
311 | ### sigpipe_status_ok
|
312 |
|
313 | If a process that's part of a pipeline exits with status 141 when this is
|
314 | option is on, it's turned into status 0, which avoids failure.
|
315 |
|
316 | SIGPIPE errors occur in cases like 'yes | head', and generally aren't useful.
|
317 |
|