Bird
0
0

What is the correct way to get the number of elements in a bash array named servers?

easy📝 Syntax Q3 of 15
Bash Scripting - Arrays
What is the correct way to get the number of elements in a bash array named servers?
Aecho ${servers}
Becho ${servers[@]}
Cecho ${#servers}
Decho ${#servers[@]}
Step-by-Step Solution
Solution:
  1. Step 1: Recall array length syntax

    ${#array[@]} returns the count of elements.
  2. Step 2: Apply to servers

    Use echo ${#servers[@]} to print number of elements.
  3. Final Answer:

    echo ${#servers[@]} -> Option D
  4. Quick Check:

    Use # and [@] to get count [OK]
Quick Trick: Use echo ${#array[@]} to print length [OK]
Common Mistakes:
MISTAKES
  • Using ${#servers} which gives length of first element
  • Using ${servers[@]} which prints all elements
  • Using ${servers} which prints first element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes