invocation-option
Bash -x script [argument ...]
Starts with execution tracing enabled. The trace normally goes to stderr and can expose expanded arguments or secrets. Use only synthetic values, and separate trace output from ordinary stdout. Unlike -v, this shows executed commands after expansion. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Expected output (one item per line): demo; trace captured.
Formal Syntax & Structure
bash syntaxbash
bash -x script [argument ...]Return Value
exit status
See the example and command status; failures are nonzero.
Working Example
Example Snippetbash
bash --noprofile --norc -x -c 'value=demo; printf "%s\n" "$value"' > output 2> trace || exit 1cat outputgrep -Fq 'printf' trace || exit 1printf 'trace captured\n'