Bird
0
0

Given the following bash script with set -o pipefail enabled, what will be the exit status?

medium📝 Predict Output Q4 of 15
Bash Scripting - Error Handling
Given the following bash script with set -o pipefail enabled, what will be the exit status?
set -o pipefail
true | false
A1
B0
C2
DThe exit status of the last command (false)
Step-by-Step Solution
Solution:
  1. Step 1: Understand pipeline behavior

    Without pipefail, the exit status is that of the last command.
  2. Step 2: Effect of set -o pipefail

    With pipefail, the pipeline returns the exit status of the rightmost failing command.
  3. Step 3: Analyze commands

    Here, true succeeds (0), false fails (1).
  4. Final Answer:

    1 -> Option A
  5. Quick Check:

    Pipeline fails if any command fails [OK]
Quick Trick: Pipefail returns first failure's exit code [OK]
Common Mistakes:
MISTAKES
  • Assuming exit status is always last command's
  • Confusing exit codes of true and false
  • Ignoring pipefail effect on pipeline status

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes