Challenge - 5 Problems
Pipefail Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this script with pipefail enabled?
Consider this bash script run with
What is the exit status of the entire pipeline?
set -o pipefail enabled:echo "hello" | grep "bye" | wc -l
What is the exit status of the entire pipeline?
Bash Scripting
set -o pipefail echo "hello" | grep "bye" | wc -l
Attempts:
2 left
💡 Hint
Remember, with pipefail, the pipeline exit status is the rightmost non-zero status or zero if all succeed.
✗ Incorrect
The grep command fails to find "bye" in "hello", so it returns exit status 1. With pipefail, the pipeline exit status is 1, not 0.
💻 Command Output
intermediate2:00remaining
What happens without pipefail in this pipeline?
Run this pipeline without
What is the exit status of the pipeline?
set -o pipefail:echo "hello" | grep "bye" | wc -l
What is the exit status of the pipeline?
Bash Scripting
echo "hello" | grep "bye" | wc -l
Attempts:
2 left
💡 Hint
Without pipefail, the pipeline exit status is the last command's exit status.
✗ Incorrect
The last command wc -l succeeds and returns 0, so the pipeline exit status is 0 even though grep failed.
📝 Syntax
advanced1:30remaining
Which command correctly enables pipefail in bash?
You want to enable pipefail in your bash script. Which command is correct?
Attempts:
2 left
💡 Hint
The correct syntax uses 'set -o' followed by the option name.
✗ Incorrect
The correct way to enable pipefail is 'set -o pipefail'. Other options are invalid syntax.
🚀 Application
advanced2:00remaining
How to detect failure in any command of a pipeline?
You want your bash script to fail if any command in a pipeline fails. Which approach works best?
Attempts:
2 left
💡 Hint
Pipefail makes the pipeline exit status reflect any failure inside it.
✗ Incorrect
'set -o pipefail' causes the pipeline to return failure if any command fails, which is what you want.
🧠 Conceptual
expert2:30remaining
Why is 'set -o pipefail' important in automation scripts?
In automation scripts, why is enabling
set -o pipefail considered a best practice?Attempts:
2 left
💡 Hint
Think about how pipelines report success or failure by default.
✗ Incorrect
Without pipefail, a pipeline returns the last command's status, hiding failures in earlier commands. Pipefail helps catch those failures.