Bird
0
0

Why is it important to use spaces around brackets in bash if conditions like [ $x -eq 5 ]?

hard🧠 Conceptual Q10 of 15
Bash Scripting - Conditionals
Why is it important to use spaces around brackets in bash if conditions like [ $x -eq 5 ]?
ABecause spaces make the script look cleaner
BBecause without spaces the shell treats brackets as part of the variable
CBecause brackets are commands and need spaces to separate arguments
DBecause spaces are optional but recommended
Step-by-Step Solution
Solution:
  1. Step 1: Understand [ ] in bash

    The square brackets are actually a command (test), so spaces separate the command and its arguments.
  2. Step 2: Explain why spaces matter

    Without spaces, the shell cannot parse the command and arguments correctly, causing errors.
  3. Final Answer:

    Because brackets are commands and need spaces to separate arguments -> Option C
  4. Quick Check:

    Spaces separate command and args in [ ] [OK]
Quick Trick: Always put spaces inside [ ] for correct parsing [OK]
Common Mistakes:
MISTAKES
  • Skipping spaces inside brackets
  • Thinking brackets are syntax, not commands
  • Assuming spaces are optional

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes