Bird
0
0

Which is the correct way to declare an array named fruits with items apple, banana, and cherry in bash?

easy📝 Syntax Q12 of 15
Bash Scripting - Arrays
Which is the correct way to declare an array named fruits with items apple, banana, and cherry in bash?
Afruits={apple; banana; cherry}
Bfruits=(apple banana cherry)
Cfruits=[apple, banana, cherry]
Dfruits=apple,banana,cherry
Step-by-Step Solution
Solution:
  1. Step 1: Recall bash array syntax

    Bash arrays use parentheses with space-separated items: array=(item1 item2).
  2. Step 2: Check each option

    Only fruits=(apple banana cherry) uses parentheses and spaces correctly.
  3. Final Answer:

    fruits=(apple banana cherry) -> Option B
  4. Quick Check:

    Array syntax = parentheses with spaces [OK]
Quick Trick: Use parentheses and spaces for arrays [OK]
Common Mistakes:
MISTAKES
  • Using square brackets like other languages
  • Separating items with commas
  • Using curly braces incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes