Bird
0
0

Which of the following is the correct syntax to store the length of a bash array files into a variable count?

easy📝 Syntax Q12 of 15
Bash Scripting - Arrays
Which of the following is the correct syntax to store the length of a bash array files into a variable count?
Acount=${files[@]}
Bcount=${#files}
Ccount=${#files[@]}
Dcount=${files}
Step-by-Step Solution
Solution:
  1. Step 1: Use correct length syntax

    To get the number of elements, use ${#files[@]}.
  2. Step 2: Assign to variable

    Assigning with count=${#files[@]} stores the array length in count.
  3. Final Answer:

    count=${#files[@]} -> Option C
  4. Quick Check:

    Variable count = ${#files[@]} [OK]
Quick Trick: Assign length with count=${#array[@]} to get element count [OK]
Common Mistakes:
MISTAKES
  • Using count=${files[@]} which assigns all elements, not length
  • Using count=${#files} which gives length of first element
  • Forgetting to use ${} around the expression

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes