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 | errtrace # Inherits ERR trap in shell functions, sub processes, sub commands (option -E)
|
105 |
|
106 | ## Compat
|
107 |
|
108 | ### eval_unsafe_arith
|
109 |
|
110 | Allow dynamically parsed `a[$(echo 42)]` For bash compatibility.
|
111 |
|
112 | ### ignore_flags_not_impl
|
113 |
|
114 | Suppress failures from flags not implemented. Example:
|
115 |
|
116 | shopt --set ignore_flags_not_impl
|
117 |
|
118 | declare -i foo=2+3 # not evaluated to 5, but doesn't fail either
|
119 |
|
120 | This option can be useful for "getting past" errors while testing.
|
121 |
|
122 | ## Groups
|
123 |
|
124 | To turn OSH into YSH, we use three option groups. Some of them allow new
|
125 | features, and some disallow old features.
|
126 |
|
127 | <!-- note: explicit anchor necessary because of mangling -->
|
128 | <h3 id="strict:all">strict:all</h3>
|
129 |
|
130 | Option in this group disallow problematic or confusing shell constructs. The
|
131 | resulting script will still run in another shell.
|
132 |
|
133 | shopt --set strict:all # turn on all options
|
134 | shopt -p strict:all # print their current state
|
135 |
|
136 | Parsing options:
|
137 |
|
138 | strict_parse_slice # No implicit length for ${a[@]::}
|
139 | X strict_parse_utf8 # Source code must be valid UTF-8
|
140 |
|
141 | Runtime options:
|
142 |
|
143 | strict_argv # No empty argv
|
144 | strict_arith # Fatal parse errors (on by default)
|
145 | strict_array # Arrays and strings aren't confused
|
146 | strict_control_flow # Disallow misplaced keyword, empty arg
|
147 | strict_errexit # Disallow code that ignores failure
|
148 | strict_nameref # Trap invalid variable names
|
149 | strict_word_eval # Expose unicode and slicing errors
|
150 | strict_tilde # Tilde subst can result in error
|
151 | X strict_glob # Parse the sublanguage more strictly
|
152 |
|
153 | <h3 id="ysh:upgrade">ysh:upgrade</h3>
|
154 |
|
155 | Options in this group enable new YSH features. It doesn't break existing shell
|
156 | scripts when it's avoidable.
|
157 |
|
158 | For example, `parse_at` means that `@myarray` is now the operation to splice
|
159 | an array. This will break scripts that expect `@` to be literal, but you can
|
160 | simply quote it like `'@literal'` to fix the problem.
|
161 |
|
162 | shopt --set ysh:upgrade # turn on all options
|
163 | shopt -p ysh:upgrade # print their current state
|
164 |
|
165 | Details on each option:
|
166 |
|
167 | parse_at echo @array @[arrayfunc(x, y)]
|
168 | parse_brace if true { ... }; cd ~/src { ... }
|
169 | parse_equals x = 'val' in Caps { } config blocks
|
170 | parse_paren if (x > 0) ...
|
171 | parse_proc proc p { ... }
|
172 | parse_triple_quote """$x""" '''x''' (command mode)
|
173 | parse_ysh_string echo r'\' u'\\' b'\\' (command mode)
|
174 | command_sub_errexit Synchronous errexit check
|
175 | process_sub_fail Analogous to pipefail for process subs
|
176 | sigpipe_status_ok status 141 -> 0 in pipelines
|
177 | simple_word_eval No splitting, static globbing
|
178 | xtrace_rich Hierarchical and process tracing
|
179 | xtrace_details (-u) Disable most tracing with +
|
180 | dashglob (-u) Disabled to avoid files like -rf
|
181 | X env_dict Copy environ into ENV dict
|
182 |
|
183 |
|
184 | <h3 id="ysh:all">ysh:all</h3>
|
185 |
|
186 | Enable the full YSH language. This includes everything in the `ysh:upgrade`
|
187 | group and the `strict:all` group.
|
188 |
|
189 | shopt --set ysh:all # turn on all options
|
190 | shopt -p ysh:all # print their current state
|
191 |
|
192 | Details on options that are not in `ysh:upgrade` and `strict:all`:
|
193 |
|
194 | parse_at_all @ starting any word is an operator
|
195 | parse_backslash (-u) Allow bad backslashes in "" and $''
|
196 | parse_backticks (-u) Allow legacy syntax `echo hi`
|
197 | parse_bare_word (-u) 'case unquoted' and 'for x in unquoted'
|
198 | parse_dollar (-u) Allow bare $ to mean \$ (maybe $/d+/)
|
199 | parse_dbracket (-u) Is legacy [[ allowed?
|
200 | parse_dparen (-u) Is (( legacy arithmetic allowed?
|
201 | parse_ignored (-u) Parse, but ignore, certain redirects
|
202 | parse_sh_arith (-u) Allow legacy shell arithmetic
|
203 | expand_aliases (-u) Whether aliases are expanded
|
204 | X no_env_vars Use $[ENV.PYTHONPATH], not $PYTHONPATH
|
205 | X old_builtins (-u) local/declare/etc. pushd/popd/dirs
|
206 | ... source unset printf [un]alias
|
207 | ... getopts
|
208 | X old_syntax (-u) ( ) ${x%prefix} ${a[@]} $$
|
209 | simple_echo echo doesn't accept flags -e -n
|
210 | simple_eval_builtin eval takes exactly 1 argument
|
211 | simple_test_builtin 3 args or fewer; use test not [
|
212 | X simple_trap Function name only
|
213 | verbose_errexit Whether to print detailed errors
|
214 |
|
215 | ## YSH Details
|
216 |
|
217 | ### opts-redefine
|
218 |
|
219 | In the interactive shell, you can redefine procs and funcs.
|
220 |
|
221 | redefine_module 'module' builtin always returns 0
|
222 | redefine_proc_func (-u) Can shell func, proc and func be redefined?
|
223 | X redefine_const Can consts be redefined?
|
224 |
|
225 | ### opts-internal
|
226 |
|
227 | These options are used by the interpreter. You generally shouldn't set them
|
228 | yourself.
|
229 |
|
230 | _allow_command_sub To implement strict_errexit, eval_unsafe_arith
|
231 | _allow_process_sub To implement strict_errexit
|
232 | dynamic_scope To implement proc and func
|
233 | _no_debug_trap Used in pipelines in job control shell
|
234 | _running_trap To disable strict_errexit
|
235 | _running_hay Hay evaluation
|
236 |
|
237 | ## Unlinked Descriptions
|
238 |
|
239 | Here are some descriptions of individual options.
|
240 |
|
241 | ### strict_control_flow
|
242 |
|
243 | Disallow `break` and `continue` at the top level, and disallow empty args like
|
244 | `return $empty`.
|
245 |
|
246 | ### strict_tilde
|
247 |
|
248 | Failed tilde expansions cause hard errors (like zsh) rather than silently
|
249 | evaluating to `~` or `~bad`.
|
250 |
|
251 |
|
252 | ### strict_nameref
|
253 |
|
254 | When `strict_nameref` is set, undefined references produce fatal errors:
|
255 |
|
256 | declare -n ref
|
257 | echo $ref # fatal error, not empty string
|
258 | ref=x # fatal error instead of decaying to non-reference
|
259 |
|
260 | References that don't contain variables also produce hard errors:
|
261 |
|
262 | declare -n ref='not a var'
|
263 | echo $ref # fatal
|
264 | ref=x # fatal
|
265 |
|
266 | ### parse_ignored
|
267 |
|
268 | For compatibility, YSH will parse some constructs it doesn't execute, like:
|
269 |
|
270 | return 0 2>&1 # redirect on control flow
|
271 |
|
272 | When this option is disabled, that statement is a syntax error.
|
273 |
|
274 | ### parse_triple_quote
|
275 |
|
276 | Parse the shell-style multi-line strings, which strip leading whitespace:
|
277 |
|
278 | echo '''
|
279 | one
|
280 | two
|
281 | '''
|
282 |
|
283 | echo """
|
284 | hello
|
285 | $name
|
286 | """
|
287 |
|
288 | (This option affects only command mode. Such strings are always parsed in
|
289 | expression mode.)
|
290 |
|
291 | ### parse_ysh_string
|
292 |
|
293 | Allow `r'\'` and `u'\\'` and `b'\\'` strings, as well as their multi-line
|
294 | versions.
|
295 |
|
296 | Since shell strings are already raw, this means that YSH just ignores the r
|
297 | prefix:
|
298 |
|
299 | echo r'\' # a single backslash
|
300 |
|
301 | J8 unicode strings:
|
302 |
|
303 | echo u'mu \u{3bc}' # mu char
|
304 |
|
305 | J8 byte strings:
|
306 |
|
307 | echo b'byte \yff'
|
308 |
|
309 | (This option affects only command mode. Such strings are always parsed in
|
310 | expression mode.)
|
311 |
|
312 | ### sigpipe_status_ok
|
313 |
|
314 | If a process that's part of a pipeline exits with status 141 when this is
|
315 | option is on, it's turned into status 0, which avoids failure.
|
316 |
|
317 | SIGPIPE errors occur in cases like 'yes | head', and generally aren't useful.
|
318 |
|