mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.29k stars 345 forks source link

interp: initial support for `set -o xtrace` #744

Closed riacataquian closed 3 years ago

riacataquian commented 3 years ago

or its shorthand, set -x: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

-x
Print a trace of simple commands, for commands, case commands, select
commands, and arithmetic for commands and their arguments or associated
word lists after they are expanded and before they are executed.

this PR is an incomplete implementation- expressions like if, expr and while among others, will silently be ignored. all trace-related code are contained in the interp/trace.go file

NOTE: side-by-side comparison with bash during development, might not behave properly when mksh and sh is used

fixes #396

riacataquian commented 3 years ago

@mvdan would you mind taking a look once more? I added some more helpers to trace.go like rawExpr and rawString to avoid direct calls to the trace fields. I'll squash the commits once you agree with the changes :)

riacataquian commented 3 years ago

Thanks for another round of helpful reviews! I am keen seeing how the code can be improved. :)

riacataquian commented 3 years ago

Ack. I totally assumed the opposite, that in this case, its better to silently error than halt the running process. But I agree, it's easier to reason about. :)

I squashed the commits, this should be ready for merging.