• + 0 comments

    !/bin/bash

    Read all lines into an array

    countries=() while IFS= read -r line; do countries+=("$line") done

    Define start and end indices (0-based)

    start=3 end=7

    Calculate length of slice

    length=$(( end - start + 1 ))

    Slice the array and print

    slice=("${countries[@]:start:length}")

    echo "${slice[@]}"