Bird
0
0

What is the output of this script?

medium📝 Command Output Q4 of 15
Bash Scripting - Arrays
What is the output of this script?
arr=(apple banana cherry)
for i in "${arr[@]}"; do echo "$i"; done
Aapple banana cherry
Bapple banana cherry
Capple banana cherry
Dapple banana cherry
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop over "${arr[@]}"

    Each element is treated separately, even if it contains spaces.
  2. Step 2: Echo prints each element on its own line

    Loop prints each fruit on a new line.
  3. Final Answer:

    apple\nbanana\ncherry -> Option B
  4. Quick Check:

    Each element printed on new line = A [OK]
Quick Trick: Looping with "${array[@]}" prints each element on separate lines [OK]
Common Mistakes:
MISTAKES
  • Expecting all elements on one line
  • Confusing "${array[@]}" with "${array[*]}"
  • Not understanding echo adds newline

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes