Bird
0
0

Why might [ -e file ] return true but [ -s file ] return false in a bash script?

hard🧠 Conceptual Q10 of 15
Bash Scripting - File Operations in Scripts
Why might [ -e file ] return true but [ -s file ] return false in a bash script?
AFile is not readable
BFile does not exist
CFile is a directory
DFile exists but is empty (size zero)
Step-by-Step Solution
Solution:
  1. Step 1: Understand -e and -s operators

    -e returns true if file exists, regardless of size. -s returns true only if file exists and size > 0.
  2. Step 2: Reason about the scenario

    If -e is true but -s is false, the file exists but is empty.
  3. Final Answer:

    File exists but is empty (size zero) -> Option D
  4. Quick Check:

    -e true and -s false means empty file [OK]
Quick Trick: -e true and -s false means file is empty [OK]
Common Mistakes:
MISTAKES
  • Assuming -s true if file exists
  • Confusing directory with file
  • Thinking unreadable files affect -s

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes