Bird
0
0

Identify the error in this bash snippet:

medium📝 Debug Q6 of 15
Bash Scripting - Conditionals
Identify the error in this bash snippet:
if [-r file.txt]; then echo "Readable"; fi
AMissing spaces inside brackets
BWrong operator used
CMissing semicolon after if
DFile name should be in quotes
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for test command

    There must be spaces after [ and before ]. The snippet lacks spaces: if [-r file.txt]; is invalid.
  2. Step 2: Confirm correct syntax

    Correct syntax is if [ -r file.txt ]; then with spaces.
  3. Final Answer:

    Missing spaces inside brackets -> Option A
  4. Quick Check:

    Spaces inside [ ] are mandatory [OK]
Quick Trick: Always put spaces after [ and before ] in tests [OK]
Common Mistakes:
MISTAKES
  • No spaces inside brackets
  • Using wrong operators
  • Forgetting semicolon or newline

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes