Bird
0
0

In bash scripting, what is the effect of using double quotes around a variable like "$path" when the variable contains spaces?

easy🧠 Conceptual Q1 of 15
Bash Scripting - Quoting and Expansion
In bash scripting, what is the effect of using double quotes around a variable like "$path" when the variable contains spaces?
AIt removes all spaces from the variable's value.
BIt preserves the spaces as part of the variable's value during expansion.
CIt treats the variable as a command instead of a string.
DIt causes a syntax error.
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable expansion

    When a variable is expanded without quotes, bash splits the value on spaces.
  2. Step 2: Effect of double quotes

    Using double quotes around $path preserves spaces, treating the entire string as a single argument.
  3. Final Answer:

    It preserves the spaces as part of the variable's value during expansion. -> Option B
  4. Quick Check:

    Test with path="My Documents"; echo "$path" prints with spaces [OK]
Quick Trick: Double quotes preserve spaces in variable values [OK]
Common Mistakes:
MISTAKES
  • Assuming spaces are removed inside double quotes
  • Not quoting variables with spaces causing word splitting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes