Bird
0
0

Given the script count.sh:

medium📝 Command Output Q5 of 15
Bash Scripting - Basics
Given the script count.sh:
#!/bin/bash
for i in {1..3}; do
echo $i
done

What is the output when run as ./count.sh?
A1 2 3
B1 2 3
Cfor i in {1..3}; do echo $i done
DError: syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand bash brace expansion and for loop

    {1..3} expands to 1 2 3, loop runs 3 times.
  2. Step 2: Each iteration echoes the current number on a new line

    Output is three lines: 1, 2, and 3.
  3. Final Answer:

    1 2 3 -> Option A
  4. Quick Check:

    Brace expansion in loop prints numbers line by line [OK]
Quick Trick: Brace expansion {1..3} loops over numbers 1 to 3 [OK]
Common Mistakes:
MISTAKES
  • Expecting output on one line separated by spaces
  • Misreading syntax causing error
  • Not understanding brace expansion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes