Bird
0
0

Which of the following is the correct syntax to slice 4 elements starting from index 3 in a Bash array named data?

easy📝 Syntax Q3 of 15
Bash Scripting - Arrays
Which of the following is the correct syntax to slice 4 elements starting from index 3 in a Bash array named data?
A${data[3:4]}
B${data[@]:3:4}
C${data:3:4}
D${data[@][3:4]}
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct array slicing syntax

    In Bash, slicing uses ${array[@]:start:length} format.
  2. Step 2: Match syntax to options

    ${data[@]:3:4} matches the correct syntax with start=3 and length=4.
  3. Final Answer:

    ${data[@]:3:4} -> Option B
  4. Quick Check:

    Correct slice syntax = ${array[@]:start:length} [OK]
Quick Trick: Use ${array[@]:start:length} for slicing arrays [OK]
Common Mistakes:
MISTAKES
  • Using square brackets inside slicing
  • Omitting @ symbol
  • Using incorrect colon placement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes