Bird
0
0

You want a script to exit with code 5 only if a file named data.txt does NOT exist. Which snippet correctly does this?

hard🚀 Application Q8 of 15
Bash Scripting - Error Handling
You want a script to exit with code 5 only if a file named data.txt does NOT exist. Which snippet correctly does this?
Aif [ -f data.txt ]; then exit 5; fi
Bif [ ! -f data.txt ]; then exit 5; fi
Cexit 5 if [ ! -f data.txt ]
Dexit 5 unless [ -f data.txt ]
Step-by-Step Solution
Solution:
  1. Step 1: Understand file test

    [ ! -f data.txt ] checks if file does NOT exist.
  2. Step 2: Use correct syntax

    The if statement with exit 5 inside runs exit only if file missing.
  3. Final Answer:

    if [ ! -f data.txt ]; then exit 5; fi -> Option B
  4. Quick Check:

    Use if + ! -f + exit N [OK]
Quick Trick: Use if [ ! -f file ] then exit N [OK]
Common Mistakes:
MISTAKES
  • Reversing condition
  • Wrong syntax for exit
  • Using invalid keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes