Bird
0
0

How would you declare a Bash indexed array numbers containing only even numbers from 2 to 10 using brace expansion?

hard🚀 Application Q9 of 15
Bash Scripting - Arrays
How would you declare a Bash indexed array numbers containing only even numbers from 2 to 10 using brace expansion?
Anumbers=[2 4 6 8 10]
Bnumbers=(2,4,6,8,10)
Cnumbers=({2..10..2})
Dnumbers={2..10..2}
Step-by-Step Solution
Solution:
  1. Step 1: Understand brace expansion with step

    Brace expansion {start..end..step} generates sequences with steps, e.g., {2..10..2} generates 2 4 6 8 10.
  2. Step 2: Use correct array declaration syntax

    Wrap brace expansion in parentheses to declare array: numbers=({2..10..2}). Other options use invalid syntax or missing parentheses.
  3. Final Answer:

    numbers=({2..10..2}) -> Option C
  4. Quick Check:

    Brace expansion with step inside parentheses = array [OK]
Quick Trick: Use numbers=({start..end..step}) for stepped arrays [OK]
Common Mistakes:
MISTAKES
  • Using commas inside array declaration
  • Using square or curly brackets instead of parentheses
  • Not wrapping brace expansion in parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes