0
0
Bash Scriptingscripting~20 mins

set -o pipefail in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pipefail Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this script with pipefail enabled?
Consider this bash script run with 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
AExit status is 0
BExit status is 2
CExit status is 1
DExit status is the exit status of wc -l
Attempts:
2 left
💡 Hint
Remember, with pipefail, the pipeline exit status is the rightmost non-zero status or zero if all succeed.
💻 Command Output
intermediate
2:00remaining
What happens without pipefail in this pipeline?
Run this pipeline without 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
AExit status is 0
BExit status is 1
CExit status is 2
DExit status is the exit status of grep
Attempts:
2 left
💡 Hint
Without pipefail, the pipeline exit status is the last command's exit status.
📝 Syntax
advanced
1:30remaining
Which command correctly enables pipefail in bash?
You want to enable pipefail in your bash script. Which command is correct?
Aset -o pipefail
Bset pipefail on
Cenable pipefail
Dset -pipefail
Attempts:
2 left
💡 Hint
The correct syntax uses 'set -o' followed by the option name.
🚀 Application
advanced
2: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?
ACheck exit status of the last command only
BUse 'set -o pipefail' before running the pipeline
CUse 'set -e' only without pipefail
DRun each command separately without a pipeline
Attempts:
2 left
💡 Hint
Pipefail makes the pipeline exit status reflect any failure inside it.
🧠 Conceptual
expert
2:30remaining
Why is 'set -o pipefail' important in automation scripts?
In automation scripts, why is enabling set -o pipefail considered a best practice?
AIt automatically retries failed commands in a pipeline.
BIt speeds up the execution of pipelines by running commands in parallel.
CIt disables error messages from pipeline commands.
DIt ensures the script detects failure in any command within a pipeline, preventing false success.
Attempts:
2 left
💡 Hint
Think about how pipelines report success or failure by default.