Bird
0
0

What will be the output of this bash script?

medium📝 Command Output Q13 of 15
Bash Scripting - Arrays
What will be the output of this bash script?
colors=(red green blue)
echo ${colors[1]}
Agreen
Bred
Cblue
Dcolors[1]
Step-by-Step Solution
Solution:
  1. Step 1: Understand array indexing in bash

    Bash arrays start at index 0, so colors[0] = red, colors[1] = green.
  2. Step 2: Identify the echoed element

    The script echoes colors[1], which is green.
  3. Final Answer:

    green -> Option A
  4. Quick Check:

    Index 1 = green [OK]
Quick Trick: Array indexes start at zero in bash [OK]
Common Mistakes:
MISTAKES
  • Thinking index starts at 1
  • Printing the variable name instead of value
  • Confusing array syntax with other languages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes