Bird
0
0

Which of the following is the correct syntax to declare an empty indexed array named items in Bash?

easy📝 Syntax Q3 of 15
Bash Scripting - Arrays
Which of the following is the correct syntax to declare an empty indexed array named items in Bash?
Aitems=''
Bitems=[]
Citems={}
Ditems=()
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to declare empty arrays in Bash

    Empty indexed arrays are declared with parentheses and no elements inside.
  2. Step 2: Evaluate each option

    items=() uses parentheses correctly. Options B and C use square and curly brackets which are invalid. items='' assigns an empty string, not an array.
  3. Final Answer:

    items=() -> Option D
  4. Quick Check:

    Empty Bash array declaration = items=() [OK]
Quick Trick: Use empty parentheses to declare empty arrays [OK]
Common Mistakes:
MISTAKES
  • Using square or curly brackets instead of parentheses
  • Assigning empty string instead of empty array
  • Forgetting parentheses altogether

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes