Recall & Review
beginner
What does
set -x do in a bash script?set -x turns on trace mode, which shows each command and its arguments as they are executed. It helps you see what the script is doing step-by-step.
Click to reveal answer
beginner
How do you turn off trace mode after using
set -x?You use set +x to stop showing commands in trace mode.
Click to reveal answer
beginner
Why is
set -x useful when writing bash scripts?It helps you find mistakes by showing exactly what commands run and in what order, like watching the script work live.
Click to reveal answer
beginner
Show a simple example of using
set -x in a bash script.#!/bin/bash
set -x
name="Alice"
echo "Hello, $name"
set +x
echo "Done"
This script shows commands as they run until set +x.
Click to reveal answer
intermediate
Can
set -x slow down your script? Why or why not?Yes, because it prints every command to the screen, which takes extra time and can clutter output.
Click to reveal answer
What command turns on trace mode in bash?
✗ Incorrect
set -x enables trace mode, showing commands as they run.
How do you stop trace mode in a bash script?
✗ Incorrect
set +x disables trace mode.
What is the main benefit of using
set -x?✗ Incorrect
Trace mode helps you debug by showing commands as they execute.
Which of these is a side effect of using
set -x?✗ Incorrect
Trace mode prints every command, making output longer and cluttered.
Where in a script should you place
set +x?✗ Incorrect
Use set +x where you want to stop showing commands.
Explain how
set -x helps when debugging a bash script.Think about how seeing each command helps you understand what the script does.
You got /4 concepts.
Describe how to use
set -x and set +x in a script to control tracing.Consider where you want to see commands and where you want normal output.
You got /4 concepts.