0

Got a bash array where the indexes start at an arbitrary number and want to get the first index of the array. Is such thing possible to do?

warg=([3]="-t" [4]="-s" [5]="-g")

I want to get the value 3, the index of the first element of warg.

Dilna
  • 405
  • 1
  • 6
  • 2
    Does this answer your question? [Get the index of the first or nth element of sparse bash array](https://stackoverflow.com/questions/59395313/get-the-index-of-the-first-or-nth-element-of-sparse-bash-array); or maybe `awk '{print $1}' <<< "${!warg[@]}"` or `printf '%s\n' "${!warg[@]}" | head -1` ... – markp-fuso Dec 17 '21 at 15:35
  • The way seems to involve storage to a non-sparse array. – Dilna Dec 17 '21 at 15:51
  • have you tried that answer? did it not work for you? the non-sparse array is just a temporary construct to allow you to find the nth index – markp-fuso Dec 17 '21 at 15:54
  • 1
    Yes, it is good. – Dilna Dec 17 '21 at 16:09

0 Answers0