Bird
0
0

What will be the output of this bash script?

medium📝 Command Output Q4 of 15
Bash Scripting - Arrays
What will be the output of this bash script?
items=(apple orange banana)
echo ${items[2]}
Aorange
Bapple
Cbanana
Ditems[2]
Step-by-Step Solution
Solution:
  1. Step 1: Understand array indexing in bash

    Arrays start at index 0, so items[2] is the third element.
  2. Step 2: Identify the third element

    The array is (apple orange banana), so index 2 is banana.
  3. Final Answer:

    banana -> Option C
  4. Quick Check:

    Index 2 = third item = banana [OK]
Quick Trick: Array indexes start at zero in bash [OK]
Common Mistakes:
MISTAKES
  • Assuming index starts at 1
  • Printing the variable name instead of value
  • Confusing element order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes