Bird
0
0

What is the output of this script?

medium📝 Command Output Q13 of 15
Bash Scripting - Loops
What is the output of this script?
for i in {3..6}; do echo $((i * 2)); done
A2 4 6 8
B3 4 5 6
C6 8 10 12
DError: invalid arithmetic
Step-by-Step Solution
Solution:
  1. Step 1: Identify loop values

    The loop variable i takes values 3, 4, 5, 6 from {3..6}.
  2. Step 2: Calculate output for each iteration

    Each iteration prints i * 2: 3*2=6, 4*2=8, 5*2=10, 6*2=12.
  3. Final Answer:

    6 8 10 12 -> Option C
  4. Quick Check:

    Multiply each i by 2 [OK]
Quick Trick: Multiply loop variable inside $(( )) for arithmetic [OK]
Common Mistakes:
MISTAKES
  • Confusing loop values with output
  • Using single parentheses instead of $(( ))
  • Expecting space-separated output on one line

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes