Bird
0
0

Consider the Bash array declaration animals=(cat dog rabbit). What will be the output of echo ${animals[2]}?

medium📝 Command Output Q4 of 15
Bash Scripting - Arrays
Consider the Bash array declaration animals=(cat dog rabbit). What will be the output of echo ${animals[2]}?
Arabbit
Bdog
Ccat
Danimals[2]
Step-by-Step Solution
Solution:
  1. Step 1: Understand array indexing

    Bash indexed arrays start at index 0.
  2. Step 2: Identify the element at index 2

    Given animals=(cat dog rabbit), index 0 is 'cat', index 1 is 'dog', and index 2 is 'rabbit'.
  3. Final Answer:

    rabbit -> Option A
  4. Quick Check:

    Check the index and element mapping [OK]
Quick Trick: Arrays start at 0; index 2 is third element [OK]
Common Mistakes:
MISTAKES
  • Assuming arrays start at index 1
  • Confusing the index with the value
  • Expecting the output to be the variable name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes