Bird
0
0

What will be the output of this command if file.txt does NOT exist?

medium📝 Command Output Q5 of 15
Linux CLI - Pipes and Redirection
What will be the output of this command if file.txt does NOT exist?
cat file.txt && echo 'Found' || echo 'Not found'
A'Not found' only
B'Found' only
CNo output
DContents of file.txt followed by 'Found'
Step-by-Step Solution
Solution:
  1. Step 1: Analyze cat command failure

    Since file.txt does not exist, cat fails and prints an error message.
  2. Step 2: Understand chaining with failure

    Because cat failed, && does not run echo 'Found'. The || runs echo 'Not found'.
  3. Final Answer:

    'Not found' only. -> Option A
  4. Quick Check:

    Failure triggers || echo [OK]
Quick Trick: || runs next command only if previous fails [OK]
Common Mistakes:
  • Expecting 'Found' to print
  • Ignoring error message from cat
  • Thinking both echoes run

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes