Bird
0
0

Why is it important to use quotes around "${array[@]}" when iterating over a Bash array?

hard🧠 Conceptual Q10 of 15
Bash Scripting - Arrays
Why is it important to use quotes around "${array[@]}" when iterating over a Bash array?
ATo preserve each element as a single word, even if it contains spaces
BTo join all elements into a single string separated by spaces
CTo prevent the array from being accessed
DTo convert all elements to uppercase automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand word splitting in Bash

    Without quotes, elements with spaces split into multiple words.
  2. Step 2: Quotes preserve each element as one word

    Using "${array[@]}" keeps elements intact during iteration.
  3. Final Answer:

    To preserve each element as a single word, even if it contains spaces -> Option A
  4. Quick Check:

    Quotes preserve element integrity = D [OK]
Quick Trick: Quote "${array[@]}" to keep elements whole during loops [OK]
Common Mistakes:
MISTAKES
  • Thinking quotes join elements instead of preserving
  • Assuming quotes change element case
  • Believing quotes prevent array access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes