Bird
0
0

What is the output of this code?

medium📝 Command Output Q5 of 15
Bash Scripting - Arrays
What is the output of this code?
arr=(10 20 30 40)
echo ${arr[@]:1:2}
A10 20
B20 30
C30 40
D20 30 40
Step-by-Step Solution
Solution:
  1. Step 1: Understand array slicing syntax

    ${arr[@]:start:length} extracts elements starting at index 'start' for 'length' elements.
  2. Step 2: Apply slicing to given array

    Starting at index 1 (20), length 2 elements are 20 and 30.
  3. Final Answer:

    20 30 -> Option B
  4. Quick Check:

    Slice from index 1 length 2 = 20 30 [OK]
Quick Trick: Use ${arr[@]:start:length} to slice array elements [OK]
Common Mistakes:
MISTAKES
  • Confusing start index or length
  • Expecting output from index 0
  • Using wrong slicing syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes