Bird
0
0

Which of the following is the correct syntax to check if file data.txt exists AND is readable using logical operators inside [ ]?

easy📝 Syntax Q3 of 15
Bash Scripting - Conditionals
Which of the following is the correct syntax to check if file data.txt exists AND is readable using logical operators inside [ ]?
A[ -e data.txt -o -r data.txt ]
B[ -e data.txt || -r data.txt ]
C[ -e data.txt && -r data.txt ]
D[ -e data.txt -a -r data.txt ]
Step-by-Step Solution
Solution:
  1. Step 1: Identify AND operator inside [ ]

    Inside [ ], -a means AND, so use it to combine two conditions.
  2. Step 2: Check file existence and readability

    -e data.txt checks if file exists, -r data.txt checks if readable. Combined with -a means both must be true.
  3. Final Answer:

    [ -e data.txt -a -r data.txt ] -> Option D
  4. Quick Check:

    AND inside [ ] = -a [OK]
Quick Trick: Use -a for AND inside [ ] to combine conditions [OK]
Common Mistakes:
MISTAKES
  • Using -o instead of -a for AND
  • Using && inside [ ]
  • Mixing operators incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes