Bird
0
0

You want to run backup.sh only if prepare.sh succeeds, but if backup.sh fails, you want to run alert.sh. Which command chaining achieves this?

hard📝 Application Q8 of 15
Linux CLI - Pipes and Redirection
You want to run backup.sh only if prepare.sh succeeds, but if backup.sh fails, you want to run alert.sh. Which command chaining achieves this?
Aprepare.sh && backup.sh || alert.sh
Bprepare.sh ; backup.sh ; alert.sh
Cprepare.sh && (backup.sh || alert.sh)
Dprepare.sh || backup.sh && alert.sh
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement

    Run backup.sh only if prepare.sh succeeds, then run alert.sh only if backup.sh fails.
  2. Step 2: Analyze options

    prepare.sh && (backup.sh || alert.sh) groups backup.sh and alert.sh with || inside parentheses, so alert.sh runs only if backup.sh fails, after prepare.sh succeeds.
  3. Final Answer:

    prepare.sh && (backup.sh || alert.sh) correctly chains commands as required. -> Option C
  4. Quick Check:

    Use parentheses to control chaining order [OK]
Quick Trick: Use parentheses to group chained commands correctly [OK]
Common Mistakes:
  • Not grouping commands, causing wrong execution
  • Using ; which runs all unconditionally
  • Confusing order of || and &&

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes