Bird
0
0

What is the output of this script?

medium📝 Command Output Q4 of 15
Bash Scripting - Loops
What is the output of this script?
for i in {1..5}; do echo $((i + 1)); done
A2 3 4 5 6 (each on a new line)
B1 2 3 4 5 (each on a new line)
C3 4 5 6 7 (each on a new line)
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop range

    The loop variable i goes from 1 to 5.
  2. Step 2: Calculate the expression inside echo

    Each iteration prints i + 1, so outputs are 2, 3, 4, 5, 6 on separate lines.
  3. Final Answer:

    2 3 4 5 6 (each on a new line) -> Option A
  4. Quick Check:

    Arithmetic inside echo with $(( )) = 2 3 4 5 6 (each on a new line) [OK]
Quick Trick: Use $(( )) for arithmetic inside loops [OK]
Common Mistakes:
MISTAKES
  • Forgetting to use $(( )) for math
  • Expecting original i values instead of i+1
  • Confusing output format (all on one line)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes