Bird
0
0

Given the Bash array arr=(a b c d e), what is the output of echo ${arr[@]:1:3}?

medium📝 Command Output Q13 of 15
Bash Scripting - Arrays
Given the Bash array arr=(a b c d e), what is the output of echo ${arr[@]:1:3}?
Aa b c
Bc d e
Cb c d e
Db c d
Step-by-Step Solution
Solution:
  1. Step 1: Identify the array and slice parameters

    The array is (a b c d e). The slice starts at index 1 and takes 3 elements.
  2. Step 2: Extract elements from index 1 to 3

    Index 0 = a, 1 = b, 2 = c, 3 = d, 4 = e. Taking 3 elements from index 1 gives: b, c, d.
  3. Final Answer:

    b c d -> Option D
  4. Quick Check:

    Slice from 1 length 3 = b c d [OK]
Quick Trick: Count from zero, pick length elements starting at start [OK]
Common Mistakes:
MISTAKES
  • Starting count at 1 instead of 0
  • Taking wrong number of elements
  • Confusing output with full array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes