0
0
Bash Scriptingscripting~10 mins

set -o pipefail in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable the pipefail option in bash.

Bash Scripting
set [1] pipefail
Drag options to blanks, or click blank then click option'
A-u
B-e
C-x
D-o
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-e' instead of '-o' disables immediate exit on error, not pipefail.
Using '-x' enables debugging, not pipefail.
2fill in blank
medium

Complete the code to check if pipefail is enabled in the current shell.

Bash Scripting
shopt [1] pipefail
Drag options to blanks, or click blank then click option'
A-u
B-o
C-p
D-s
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-s' sets an option instead of showing it.
Using '-p' or '-u' are invalid for this purpose.
3fill in blank
hard

Fix the error in the code to enable pipefail correctly.

Bash Scripting
set [1] pipefail
Drag options to blanks, or click blank then click option'
A-e
B-p
C-o
D-x
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-e' instead of '-o' causes the command to not enable pipefail.
Using '-p' or '-x' are unrelated options.
4fill in blank
hard

Fill both blanks to create a pipeline that fails if any command fails, using pipefail.

Bash Scripting
set [1] pipefail
cat file.txt | grep 'hello' | [2]
Drag options to blanks, or click blank then click option'
A-o
Bsort
Cwc -l
Dawk '{print $1}'
Attempts:
3 left
💡 Hint
Common Mistakes
Not enabling pipefail causes the pipeline to ignore failures.
Using 'sort' or 'awk' changes the output meaning.
5fill in blank
hard

Fill all three blanks to create a script that enables pipefail, runs a pipeline, and checks the exit status.

Bash Scripting
set [1] pipefail
output=$(cat file.txt | grep 'error' | [2])
if [[ $? [3] 0 ]]; then echo "Success"; else echo "Failure"; fi
Drag options to blanks, or click blank then click option'
A-o
Bwc -l
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' reverses the success check.
Not enabling pipefail causes false success.