Bird
0
0

Given a bash array nums=(5 10 15 20 25), which snippet correctly prints Length is 5?

hard🚀 Application Q8 of 15
Bash Scripting - Arrays
Given a bash array nums=(5 10 15 20 25), which snippet correctly prints Length is 5?
Aecho "Length is ${#nums[@]}"
Becho "Length is ${#nums}"
Cecho "Length is ${nums[@]}"
Decho "Length is ${nums}"
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct length syntax

    ${#nums[@]} returns number of elements.
  2. Step 2: Construct echo statement

    Use echo "Length is ${#nums[@]}" to print desired output.
  3. Final Answer:

    echo "Length is ${#nums[@]}" -> Option A
  4. Quick Check:

    Use # and [@] inside echo [OK]
Quick Trick: Print length with echo "${#array[@]}" [OK]
Common Mistakes:
MISTAKES
  • Using ${#nums} which gives length of first element
  • Printing ${nums[@]} which prints all elements
  • Printing ${nums} which prints first element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes