0
0
Linux CLIscripting~5 mins

Shell options (set -e, set -x) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the shell option set -e do in a script?

set -e makes the script stop running immediately if any command returns an error (non-zero exit code). This helps catch problems early.

Click to reveal answer
beginner
What is the purpose of set -x in a shell script?

set -x turns on debugging mode. It shows each command and its arguments as they run, so you can see what the script is doing step-by-step.

Click to reveal answer
beginner
How can set -e help in real-life scripting?

It stops the script when something goes wrong, like a missing file or failed command. This prevents errors from causing bigger problems later.

Click to reveal answer
intermediate
How do you turn off the effects of set -x in a script?

You use set +x to stop showing commands as they run. This is useful to reduce clutter after debugging.

Click to reveal answer
intermediate
What happens if you run a script with set -e and a command fails inside a loop?

The script will stop immediately at the failed command, even inside loops, unless you handle errors explicitly.

Click to reveal answer
What does set -e do in a shell script?
ARuns the script in the background
BShows each command before running it
CIgnores errors and continues
DStops the script if any command fails
Which option shows commands as they run for debugging?
Aset -e
Bset -x
Cset +e
Dset +x
How do you disable the debugging mode started by set -x?
Aset +x
Bset -n
Cset -e
Dset +e
If a command fails inside a loop with set -e, what happens?
AThe script ignores the error and continues
BThe loop skips the failed command and continues
CThe script stops immediately
DThe loop restarts from the beginning
Why would you use set -e in a script?
ATo stop on errors and avoid unexpected results
BTo speed up the script
CTo debug commands
DTo run commands silently
Explain what set -e and set -x do in a shell script and why they are useful.
Think about error handling and debugging.
You got /4 concepts.
    Describe a situation where using set -e would prevent a problem in a script.
    Imagine a script copying files or installing software.
    You got /4 concepts.