Bird
0
0

In bash scripting, what issue arises if you reference a variable containing spaces without using quotes?

easy🧠 Conceptual Q1 of 15
Bash Scripting - Quoting and Expansion
In bash scripting, what issue arises if you reference a variable containing spaces without using quotes?
AThe variable splits into multiple arguments causing command errors
BThe variable is treated as a single string regardless of spaces
CThe shell automatically escapes spaces, so no issue occurs
DThe variable is ignored by the shell
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable expansion

    When a variable contains spaces and is unquoted, bash splits it into separate words.
  2. Step 2: Effect on commands

    This splitting causes commands to receive multiple arguments instead of one, leading to errors.
  3. Final Answer:

    The variable splits into multiple arguments causing command errors -> Option A
  4. Quick Check:

    Unquoted variables with spaces split [OK]
Quick Trick: Always quote variables with spaces to avoid splitting [OK]
Common Mistakes:
MISTAKES
  • Assuming spaces are preserved without quotes
  • Believing shell auto-quotes variables
  • Ignoring errors caused by word splitting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes