Bird
0
0

Given this script snippet with set -e enabled:

medium📝 Command Output Q13 of 15
Linux CLI - Environment and Configuration
Given this script snippet with set -e enabled:
set -e
mkdir /tmp/mydir
cd /tmp/mydir
false
echo "This will not print"
What will be the output when running this script?
AFails at mkdir and stops immediately
BCreates directory, changes directory, prints 'This will not print'
CCreates directory, changes directory, then stops at false; no echo output
DRuns all commands including echo
Step-by-Step Solution
Solution:
  1. Step 1: Trace commands with set -e

    The script creates /tmp/mydir, changes into it, then runs false which returns error (non-zero).
  2. Step 2: Effect of set -e on error

    Because set -e stops on any error, the script stops after false and does not run the echo command.
  3. Final Answer:

    Creates directory, changes directory, then stops at false; no echo output -> Option C
  4. Quick Check:

    set -e stops script on error [OK]
Quick Trick: Remember: script stops at first error with set -e [OK]
Common Mistakes:
  • Assuming echo runs after error
  • Thinking mkdir fails by default
  • Ignoring effect of set -e

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes