Bird
0
0

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

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

    Run backup.sh only if prepare.sh succeeds; if prepare.sh fails, run cleanup.sh.
  2. Step 2: Analyze prepare.sh && backup.sh || cleanup.sh

    prepare.sh && backup.sh || cleanup.sh means: if prepare.sh succeeds, run backup.sh. If either prepare.sh or backup.sh fails, run cleanup.sh. This matches the requirement.
  3. Final Answer:

    prepare.sh && backup.sh || cleanup.sh -> Option D
  4. Quick Check:

    Run backup if prepare succeeds, else cleanup [OK]
Quick Trick: Use && then || to handle success and failure paths [OK]
Common Mistakes:
  • Running cleanup even if prepare succeeds
  • Running backup even if prepare fails
  • Using ; which ignores success/failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes