Trace the commands actually executed after variable expansion and branching.
Show each command immediately before execution.
Which command is appropriate?
bash -x enables xtrace and writes expanded simple commands to standard error before execution. Avoid exposing secrets in traced values.
Detailed explanation
bash -n script.shIncorrect. bash -n checks syntax without normal execution.
Incorrect. bash -n checks syntax without normal execution.
bash -v script.shIncorrect. bash -v shows input lines before expansion.
Incorrect. bash -v shows input lines before expansion.
bash -e script.shIncorrect. bash -e changes exit behavior after failures; it is not the tracing option.
Incorrect. bash -e changes exit behavior after failures; it is not the tracing option.
bash -x script.shCorrect. bash -x traces expanded commands just before execution.
Correct. bash -x traces expanded commands just before execution.
Try it yourself
An example you can run in a temporary verification environment.
bash -c 'f=$(mktemp); printf "name=blue\nprintf \"%%s\\n\" \"$name\"\n" >"$f"; bash -x "$f" 2>&1; rm -f "$f"'Expected result
+ name=blue、+ printf ... blueの追跡とblueの実行結果Key points
- -x enables execution tracing
- It shows expanded commands
- Do not expose secrets
Notes
- Environment: GNU Bash 5.2 / 一時ファイル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.