Run script.sh while displaying shell input lines as Bash reads them.
Use verbose input display, not expanded command tracing.
Which command is appropriate?
bash -v displays shell input lines as they are read. bash -x instead shows commands after expansion immediately before execution.
Detailed explanation
bash -n script.shIncorrect. bash -n only checks syntax and does not execute the script.
Incorrect. bash -n only checks syntax and does not execute the script.
bash -c script.shIncorrect. bash -c treats script.sh as command text rather than enabling file verbose mode.
Incorrect. bash -c treats script.sh as command text rather than enabling file verbose mode.
bash -v script.shCorrect. bash -v script.sh displays input lines while executing the file.
Correct. bash -v script.sh displays input lines while executing the file.
bash -x script.shIncorrect. bash -x traces expanded commands rather than raw input lines.
Incorrect. bash -x traces expanded commands rather than raw input lines.
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 -v "$f" 2>&1; rm -f "$f"'Expected result
入力行name=blueとprintf行、および実行結果Key points
- -v displays input lines
- Output goes to standard error
- -x displays expanded commands
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.