Bird
0
0

What will this Bash for loop output?

easy🧠 Conceptual Q2 of 15
Bash Scripting - Loops
What will this Bash for loop output?
for animal in cat dog bird; do echo "$animal"; done
Acat dog bird
Bcatdogbird
Ccat\ndog\nbird (each on a new line)
DError: syntax incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop

    The loop iterates over the list: cat, dog, bird.
  2. Step 2: Echo command

    Each iteration prints the current animal followed by a newline.
  3. Final Answer:

    cat\ndog\nbird (each on a new line) -> Option C
  4. Quick Check:

    Each item is printed on its own line [OK]
Quick Trick: For loops print each item on a new line by default [OK]
Common Mistakes:
MISTAKES
  • Thinking all items print on one line
  • Assuming syntax error due to quotes
  • Confusing concatenation with separate prints

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes