Bird
0
0

How would you write a command chain to run cmd1, then cmd2 only if cmd1 fails, and finally cmd3 regardless of previous results?

hard📝 Application Q9 of 15
Linux CLI - Pipes and Redirection
How would you write a command chain to run cmd1, then cmd2 only if cmd1 fails, and finally cmd3 regardless of previous results?
Acmd1 || cmd2 ; cmd3
Bcmd1 && cmd2 || cmd3
Ccmd1 ; cmd2 && cmd3
Dcmd1 && cmd2 ; cmd3
Step-by-Step Solution
Solution:
  1. Step 1: Understand chaining requirements

    Run cmd2 only if cmd1 fails, so use cmd1 || cmd2.
  2. Step 2: Run cmd3 always

    Use ; to run cmd3 regardless of previous commands.
  3. Final Answer:

    cmd1 || cmd2 ; cmd3 runs cmd3 always, cmd2 only if cmd1 fails. -> Option A
  4. Quick Check:

    || for failure, ; for unconditional [OK]
Quick Trick: Use || for failure, ; for always run next [OK]
Common Mistakes:
  • Using && instead of || for failure
  • Using && before ; incorrectly
  • Expecting && to run on failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes