Bird
0
0

Which of the following is the correct syntax to print numbers 1 to 10 in Bash using a for loop with brace expansion?

easy📝 Syntax Q3 of 15
Bash Scripting - Loops
Which of the following is the correct syntax to print numbers 1 to 10 in Bash using a for loop with brace expansion?
Afor i in {1..10} echo $i done
Bfor i in {1..10}; do echo $i; done
Cfor i {1..10}; do echo $i; done
Dfor i in {1..10}; do echo i; done
Step-by-Step Solution
Solution:
  1. Step 1: Check for correct loop syntax

    The for loop requires 'in' keyword, the range in braces, and 'do' and 'done' keywords.
  2. Step 2: Verify echo command usage

    Variable $i must be referenced with a dollar sign to print its value.
  3. Final Answer:

    for i in {1..10}; do echo $i; done -> Option B
  4. Quick Check:

    Correct for loop syntax with echo $i = for i in {1..10}; do echo $i; done [OK]
Quick Trick: Use 'do' and 'done' with for loops; echo variables with $ [OK]
Common Mistakes:
MISTAKES
  • Omitting 'do' and 'done'
  • Not using $ before variable in echo
  • Missing 'in' keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes