1 |
# Oil xtrace |
2 |
|
3 |
#### Customize PS4 |
4 |
shopt -s oil:upgrade |
5 |
set -x |
6 |
|
7 |
# Reuse the default |
8 |
PS4='$LINENO '"$PS4" |
9 |
echo 1; echo 2 |
10 |
echo 3 |
11 |
## STDOUT: |
12 |
1 |
13 |
2 |
14 |
3 |
15 |
## END |
16 |
## STDERR: |
17 |
5 . builtin echo 1 |
18 |
5 . builtin echo 2 |
19 |
6 . builtin echo 3 |
20 |
## END |
21 |
|
22 |
|
23 |
#### xtrace_details doesn't show [[ ]] etc. |
24 |
shopt -s oil:upgrade |
25 |
set -x |
26 |
|
27 |
dir=/ |
28 |
if [[ -d $dir ]]; then |
29 |
(( a = 42 )) |
30 |
fi |
31 |
cd / |
32 |
|
33 |
## stdout-json: "" |
34 |
## STDERR: |
35 |
. builtin cd '/' |
36 |
## END |
37 |
|
38 |
#### xtrace_details AND xtrace_rich on |
39 |
shopt -s oil:upgrade xtrace_details |
40 |
shopt --unset errexit |
41 |
set -x |
42 |
|
43 |
{ |
44 |
env false |
45 |
set +x |
46 |
} 2>err.txt |
47 |
|
48 |
sed --regexp-extended 's/[[:digit:]]{2,}/12345/g' err.txt >&2 |
49 |
|
50 |
## STDOUT: |
51 |
## END |
52 |
## STDERR: |
53 |
| command 12345: env false |
54 |
; process 12345: status 1 |
55 |
. builtin set '+x' |
56 |
## END |
57 |
|
58 |
#### proc and shell function |
59 |
shopt --set oil:upgrade |
60 |
set -x |
61 |
|
62 |
shfunc() { |
63 |
: $1 |
64 |
} |
65 |
|
66 |
proc p { |
67 |
: $1 |
68 |
} |
69 |
|
70 |
shfunc 1 |
71 |
p 2 |
72 |
## stdout-json: "" |
73 |
## STDERR: |
74 |
> proc shfunc 1 |
75 |
. builtin ':' 1 |
76 |
< proc shfunc |
77 |
> proc p 2 |
78 |
. builtin ':' 2 |
79 |
< proc p |
80 |
## END |
81 |
|
82 |
#### eval |
83 |
shopt --set oil:upgrade |
84 |
set -x |
85 |
|
86 |
eval 'echo 1; echo 2' |
87 |
## STDOUT: |
88 |
1 |
89 |
2 |
90 |
## END |
91 |
## STDERR: |
92 |
> eval |
93 |
. builtin echo 1 |
94 |
. builtin echo 2 |
95 |
< eval |
96 |
## END |
97 |
|
98 |
#### source |
99 |
echo 'echo source-argv: "$@"' > lib.sh |
100 |
|
101 |
shopt --set oil:upgrade |
102 |
set -x |
103 |
|
104 |
source lib.sh 1 2 3 |
105 |
|
106 |
## STDOUT: |
107 |
source-argv: 1 2 3 |
108 |
## END |
109 |
## STDERR: |
110 |
> source lib.sh 1 2 3 |
111 |
. builtin echo 'source-argv:' 1 2 3 |
112 |
< source lib.sh |
113 |
## END |
114 |
|
115 |
#### external and builtin |
116 |
shopt --set oil:upgrade |
117 |
shopt --unset errexit |
118 |
set -x |
119 |
|
120 |
{ |
121 |
env false |
122 |
true |
123 |
set +x |
124 |
} 2>err.txt |
125 |
|
126 |
# normalize PIDs, assumed to be 2 or more digits |
127 |
sed --regexp-extended 's/[[:digit:]]{2,}/12345/g' err.txt >&2 |
128 |
|
129 |
## stdout-json: "" |
130 |
## STDERR: |
131 |
| command 12345: env false |
132 |
; process 12345: status 1 |
133 |
. builtin true |
134 |
. builtin set '+x' |
135 |
## END |
136 |
|
137 |
#### subshell |
138 |
shopt --set oil:upgrade |
139 |
shopt --unset errexit |
140 |
set -x |
141 |
|
142 |
proc p { |
143 |
: p |
144 |
} |
145 |
|
146 |
{ |
147 |
: begin |
148 |
( |
149 |
: 1 |
150 |
p |
151 |
exit 3 |
152 |
) |
153 |
set +x |
154 |
} 2>err.txt |
155 |
|
156 |
# Hack: sort for determinism |
157 |
sed --regexp-extended 's/[[:digit:]]{2,}/12345/g' err.txt | LANG=C sort >&2 |
158 |
|
159 |
## stdout-json: "" |
160 |
## STDERR: |
161 |
. 12345 builtin ':' p |
162 |
+ 12345 exit 3 |
163 |
. 12345 builtin ':' 1 |
164 |
< 12345 proc p |
165 |
> 12345 proc p |
166 |
. builtin ':' begin |
167 |
. builtin set '+x' |
168 |
; process 12345: status 3 |
169 |
| forkwait 12345 |
170 |
## END |
171 |
|
172 |
#### command sub |
173 |
shopt --set oil:upgrade |
174 |
set -x |
175 |
|
176 |
{ |
177 |
echo foo=$(echo bar) |
178 |
set +x |
179 |
|
180 |
} 2>err.txt |
181 |
|
182 |
# HACK: sort because xtrace output has non-determinism. |
183 |
# This is arguably a bug -- see issue #995. |
184 |
# The real fix might be to sys.stderr.flush() in few places? |
185 |
sed --regexp-extended 's/[[:digit:]]{2,}/12345/g' err.txt | LANG=C sort >&2 |
186 |
|
187 |
## STDOUT: |
188 |
foo=bar |
189 |
## END |
190 |
## STDERR: |
191 |
. 12345 builtin echo bar |
192 |
. builtin echo 'foo=bar' |
193 |
. builtin set '+x' |
194 |
; process 12345: status 0 |
195 |
| command sub 12345 |
196 |
## END |
197 |
|
198 |
#### process sub (nondeterministic) |
199 |
shopt --set oil:upgrade |
200 |
shopt --unset errexit |
201 |
set -x |
202 |
|
203 |
# we wait() for them all at the end |
204 |
|
205 |
{ |
206 |
: begin |
207 |
cat <(seq 2) <(echo 1) |
208 |
set +x |
209 |
} 2>err.txt |
210 |
|
211 |
# SORT for determinism |
212 |
sed --regexp-extended 's/[[:digit:]]{2,}/12345/g; s|/fd/.|/fd/N|g' err.txt | |
213 |
LC_ALL=C sort >&2 |
214 |
#cat err.txt >&2 |
215 |
|
216 |
## STDOUT: |
217 |
1 |
218 |
2 |
219 |
1 |
220 |
## END |
221 |
|
222 |
## STDERR: |
223 |
. 12345 builtin echo 1 |
224 |
. 12345 exec seq 2 |
225 |
. builtin ':' begin |
226 |
. builtin set '+x' |
227 |
; process 12345: status 0 |
228 |
; process 12345: status 0 |
229 |
; process 12345: status 0 |
230 |
| command 12345: cat '/dev/fd/N' '/dev/fd/N' |
231 |
| proc sub 12345 |
232 |
| proc sub 12345 |
233 |
## END |
234 |
|
235 |
#### pipeline (nondeterministic) |
236 |
shopt --set oil:upgrade |
237 |
set -x |
238 |
|
239 |
myfunc() { |
240 |
echo 1 |
241 |
echo 2 |
242 |
} |
243 |
|
244 |
{ |
245 |
: begin |
246 |
myfunc | sort | wc -l |
247 |
set +x |
248 |
} 2>err.txt |
249 |
|
250 |
# SORT for determinism |
251 |
sed --regexp-extended 's/[[:digit:]]{2,}/12345/g; s|/fd/.|/fd/N|g' err.txt | |
252 |
LC_ALL=C sort >&2 |
253 |
|
254 |
## STDOUT: |
255 |
2 |
256 |
## END |
257 |
## STDERR: |
258 |
. 12345 builtin echo 1 |
259 |
. 12345 builtin echo 2 |
260 |
. 12345 exec sort |
261 |
< 12345 proc myfunc |
262 |
> 12345 proc myfunc |
263 |
; process 12345: status 0 |
264 |
; process 12345: status 0 |
265 |
; process 12345: status 0 |
266 |
| command 12345: wc -l |
267 |
| part 12345 |
268 |
| part 12345 |
269 |
. builtin ':' begin |
270 |
. builtin set '+x' |
271 |
< pipeline |
272 |
> pipeline |
273 |
## END |
274 |
|
275 |
#### singleton pipeline |
276 |
|
277 |
# Hm extra tracing |
278 |
|
279 |
shopt --set oil:upgrade |
280 |
set -x |
281 |
|
282 |
: begin |
283 |
! false |
284 |
: end |
285 |
|
286 |
## stdout-json: "" |
287 |
## STDERR: |
288 |
. builtin ':' begin |
289 |
> pipeline |
290 |
. builtin false |
291 |
< pipeline |
292 |
. builtin ':' end |
293 |
## END |
294 |
|
295 |
#### Background pipeline (separate code path) |
296 |
|
297 |
shopt --set oil:upgrade |
298 |
shopt --unset errexit |
299 |
set -x |
300 |
|
301 |
myfunc() { |
302 |
echo 2 |
303 |
echo 1 |
304 |
} |
305 |
|
306 |
{ |
307 |
: begin |
308 |
myfunc | sort | grep ZZZ & |
309 |
wait |
310 |
echo status=$? |
311 |
set +x |
312 |
} 2>err.txt |
313 |
|
314 |
# SORT for determinism |
315 |
sed --regexp-extended 's/[[:digit:]]{2,}/12345/g' err.txt | |
316 |
LC_ALL=C sort >&2 |
317 |
|
318 |
## STDOUT: |
319 |
status=0 |
320 |
## END |
321 |
## STDERR: |
322 |
. 12345 builtin echo 1 |
323 |
. 12345 builtin echo 2 |
324 |
. 12345 exec grep ZZZ |
325 |
. 12345 exec sort |
326 |
; process 12345: status 0 |
327 |
; process 12345: status 0 |
328 |
; process 12345: status 1 |
329 |
< 12345 proc myfunc |
330 |
> 12345 proc myfunc |
331 |
. builtin ':' begin |
332 |
. builtin echo 'status=0' |
333 |
. builtin set '+x' |
334 |
< wait |
335 |
> wait |
336 |
| part 12345 |
337 |
| part 12345 |
338 |
| part 12345 |
339 |
## END |
340 |
|
341 |
#### Background process with fork and & (nondeterministic) |
342 |
shopt --set oil:upgrade |
343 |
set -x |
344 |
|
345 |
{ |
346 |
sleep 0.1 & |
347 |
wait |
348 |
|
349 |
shopt -s oil:upgrade |
350 |
|
351 |
fork { |
352 |
sleep 0.1 |
353 |
} |
354 |
wait |
355 |
set +x |
356 |
} 2>err.txt |
357 |
|
358 |
# SORT for determinism |
359 |
sed --regexp-extended 's/[[:digit:]]{2,}/12345/g' err.txt | |
360 |
LC_ALL=C sort >&2 |
361 |
|
362 |
## stdout-json: "" |
363 |
## STDERR: |
364 |
. 12345 exec sleep 0.1 |
365 |
. 12345 exec sleep 0.1 |
366 |
; process 12345: status 0 |
367 |
; process 12345: status 0 |
368 |
. builtin fork |
369 |
. builtin set '+x' |
370 |
. builtin shopt -s 'oil:upgrade' |
371 |
< wait |
372 |
< wait |
373 |
> wait |
374 |
> wait |
375 |
| fork 12345 |
376 |
| fork 12345 |
377 |
## END |
378 |
|
379 |
# others: redirects? |
380 |
|
381 |
#### here doc |
382 |
shopt --set oil:upgrade |
383 |
shopt --unset errexit |
384 |
set -x |
385 |
|
386 |
{ |
387 |
: begin |
388 |
tac <<EOF |
389 |
3 |
390 |
2 |
391 |
EOF |
392 |
|
393 |
set +x |
394 |
} 2>err.txt |
395 |
|
396 |
sed --regexp-extended 's/[[:digit:]]{2,}/12345/g' err.txt >&2 |
397 |
|
398 |
## STDOUT: |
399 |
2 |
400 |
3 |
401 |
## END |
402 |
## STDERR: |
403 |
. builtin ':' begin |
404 |
| here doc 12345 |
405 |
| command 12345: tac |
406 |
; process 12345: status 0 |
407 |
; process 12345: status 0 |
408 |
. builtin set '+x' |
409 |
## END |
410 |
|
411 |
#### Two here docs |
412 |
|
413 |
# BUG: This trace shows an extra process? |
414 |
|
415 |
shopt --set oil:upgrade |
416 |
shopt --unset errexit |
417 |
set -x |
418 |
|
419 |
{ |
420 |
cat - /dev/fd/3 <<EOF 3<<EOF2 |
421 |
xx |
422 |
yy |
423 |
EOF |
424 |
zz |
425 |
EOF2 |
426 |
|
427 |
set +x |
428 |
} 2>err.txt |
429 |
|
430 |
sed --regexp-extended 's/[[:digit:]]{2,}/12345/g' err.txt >&2 |
431 |
|
432 |
## STDOUT: |
433 |
xx |
434 |
yy |
435 |
zz |
436 |
## END |
437 |
## STDERR: |
438 |
| here doc 12345 |
439 |
| here doc 12345 |
440 |
| command 12345: cat - '/dev/fd/3' |
441 |
; process 12345: status 0 |
442 |
; process 12345: status 0 |
443 |
; process 12345: status 0 |
444 |
. builtin set '+x' |
445 |
## END |
446 |
|
447 |
#### Control Flow |
448 |
shopt --set oil:upgrade |
449 |
set -x |
450 |
|
451 |
for i in 1 2 3 { |
452 |
echo $i |
453 |
if (i === '2') { |
454 |
break |
455 |
} |
456 |
} |
457 |
## STDOUT: |
458 |
1 |
459 |
2 |
460 |
## END |
461 |
## STDERR: |
462 |
. builtin echo 1 |
463 |
. builtin echo 2 |
464 |
+ break |
465 |
## END |
466 |
|
467 |
#### QSN encoded argv |
468 |
shopt --set oil:upgrade |
469 |
set -x |
470 |
|
471 |
echo $'one two\n' $'\u03bc' |
472 |
## STDOUT: |
473 |
one two |
474 |
μ |
475 |
## END |
476 |
## STDERR: |
477 |
. builtin echo 'one two\n' 'μ' |
478 |
## END |