Bird
0
0

Consider this script snippet with set -o pipefail enabled:

medium📝 Command Output Q13 of 15
Bash Scripting - Error Handling
Consider this script snippet with set -o pipefail enabled:
set -o pipefail
false | true | true
echo $? 
What will be the output?
A1
B0
C2
D3
Step-by-Step Solution
Solution:
  1. Step 1: Understand commands in pipeline

    The first command false returns exit status 1 (failure), the others return 0 (success).
  2. Step 2: Effect of set -o pipefail

    With pipefail, the pipeline exit status is the exit status of the last failed command, which is 1.
  3. Final Answer:

    1 -> Option A
  4. Quick Check:

    Pipeline exit status = last failure = 1 [OK]
Quick Trick: With pipefail, pipeline returns last error code [OK]
Common Mistakes:
MISTAKES
  • Assuming output is 0 because last command succeeds
  • Thinking output is sum of exit codes
  • Confusing exit codes with command count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes