Bird
0
0

Find the bug in this script:

medium📝 Debug Q7 of 15
Bash Scripting - Arrays
Find the bug in this script:
myarr=(1 2 3 4)
len=${#myarr[@]}
echo len
ALength syntax is incorrect
BArray declaration is wrong
Cecho len prints the word 'len' instead of variable value
DNo bug, script works correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check echo command

    echo len prints the literal string 'len', not the variable value.
  2. Step 2: Correct usage

    Use echo $len to print the value stored in variable len.
  3. Final Answer:

    echo len prints the word 'len' instead of variable value -> Option C
  4. Quick Check:

    Use $ before variable to print its value [OK]
Quick Trick: Use $ before variable name to print its value [OK]
Common Mistakes:
MISTAKES
  • Forgetting $ before variable in echo
  • Assuming echo prints variable by name
  • Confusing variable and string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes