Bird
0
0

What will be the output of this script if myfile.txt does not exist?

medium📝 Command Output Q13 of 15
Bash Scripting - File Operations in Scripts
What will be the output of this script if myfile.txt does not exist?
if [ -e myfile.txt ]; then
  echo "Found"
else
  echo "Not Found"
fi
ANot Found
BSyntax error
CFound
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition

    The condition [ -e myfile.txt ] checks if the file exists.
  2. Step 2: Evaluate the file existence

    Since myfile.txt does not exist, the condition is false, so the else branch runs.
  3. Final Answer:

    Not Found -> Option A
  4. Quick Check:

    File missing triggers else branch [OK]
Quick Trick: If file missing, else branch runs [OK]
Common Mistakes:
MISTAKES
  • Assuming output is 'Found' even if file missing
  • Confusing -e with other test operators
  • Missing else branch handling

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes