Bird
0
0

Given files=("a.txt" "b.txt" "c.txt"), what does echo ${files[2]} output?

medium📝 Command Output Q4 of 15
Bash Scripting - Arrays
Given files=("a.txt" "b.txt" "c.txt"), what does echo ${files[2]} output?
Ac.txt
Bb.txt
Ca.txt
Dfiles[2]
Step-by-Step Solution
Solution:
  1. Step 1: Identify array elements and indexes

    Array elements: index 0 = a.txt, index 1 = b.txt, index 2 = c.txt.
  2. Step 2: Access element at index 2

    echo ${files[2]} prints the element at index 2, which is c.txt.
  3. Final Answer:

    c.txt -> Option A
  4. Quick Check:

    Element at index 2 = c.txt [OK]
Quick Trick: Index 2 means third element in zero-based arrays [OK]
Common Mistakes:
MISTAKES
  • Confusing index 2 with index 1
  • Printing variable name instead of value
  • Assuming 1-based indexing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes