Bird
0
0

Given the script:

medium📝 Command Output Q5 of 15
Bash Scripting - Arrays
Given the script:
myarr=(a b c d e)
len=${#myarr[@]}
echo $len

What will be printed?
AError: len not set
B5
Ca
D4
Step-by-Step Solution
Solution:
  1. Step 1: Count elements in myarr

    The array has 5 elements: a, b, c, d, e.
  2. Step 2: Assign length to len and print

    len=${#myarr[@]} stores 5, then echo $len prints 5.
  3. Final Answer:

    5 -> Option B
  4. Quick Check:

    Array length stored and printed correctly = 5 [OK]
Quick Trick: Use ${#array[@]} to get count, then echo variable [OK]
Common Mistakes:
MISTAKES
  • Printing first element instead of length
  • Forgetting to use @ in length syntax
  • Assuming zero-based count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes