Bird
0
0

In bash, what does the expression ${#mylist[@]} evaluate to if mylist is an array?

easy🧠 Conceptual Q1 of 15
Bash Scripting - Arrays
In bash, what does the expression ${#mylist[@]} evaluate to if mylist is an array?
AThe length of the first element in the array
BThe total number of elements in the array
CThe sum of all elements in the array
DThe last element of the array
Step-by-Step Solution
Solution:
  1. Step 1: Understand the syntax

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

    Since mylist is an array, ${#mylist[@]} gives the number of elements.
  3. Final Answer:

    The total number of elements in the array -> Option B
  4. Quick Check:

    Count elements, not length of elements [OK]
Quick Trick: Use ${#array[@]} for element count [OK]
Common Mistakes:
MISTAKES
  • Confusing ${#array} with ${#array[@]}
  • Thinking it returns length of first element
  • Assuming it sums numeric values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes