Bird
0
0

How does set -o pipefail interact with command substitution in bash?

hard🚀 Application Q9 of 15
Bash Scripting - Error Handling
How does set -o pipefail interact with command substitution in bash?
Consider:
set -o pipefail
output=$(false | true)
AThe command substitution returns exit status 0 regardless of pipefail.
BThe command substitution returns the exit status of the first failed command due to pipefail.
CPipefail has no effect inside command substitution.
DThe script will error out immediately.
Step-by-Step Solution
Solution:
  1. Step 1: Understand command substitution exit status

    Command substitution returns the exit status of the entire pipeline inside it.
  2. Step 2: Effect of pipefail inside command substitution

    With pipefail enabled, the substitution returns the exit status of the rightmost failed command in the pipeline.
  3. Final Answer:

    The command substitution returns the exit status of the first failed command due to pipefail. -> Option B
  4. Quick Check:

    Pipefail affects command substitution exit status [OK]
Quick Trick: Pipefail affects exit status inside command substitution [OK]
Common Mistakes:
MISTAKES
  • Assuming command substitution always returns 0
  • Ignoring pipefail effect inside substitutions
  • Expecting immediate script error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes