0

here is a sample code

astr[10]=a
astr[20]=b
astr[30]=b
astrR="astr[@]"
echo ${!astr[@]} #the indexes
echo ${!astrR} #the values
#FAIL: echo ${!!astrR}

astrR="!astr[@]" # wild guess
echo ${!astrR} # empty output, so I am still wild

So, how to get the indexes using astrR ?

6
  • I found no question like this one, but I actually just found a way to answer it here: unix.stackexchange.com/a/390763/30352, so I thought was good to keep this question. Commented Jan 21, 2019 at 15:02
  • I'm not quite sure what you are trying to do with astrR? Are you trying to print indices and values of the associative array? Commented Jan 21, 2019 at 16:56
  • Can you explain the use-case you are trying to solve? Commented Jan 21, 2019 at 17:08
  • I get the array name as a function param, then I need to modify the external array using the reference and keeping the indexes, for that I needed a way to access the external array by it's name (as a not known variable) to maintain it (add, remove items etc) Commented Jan 21, 2019 at 22:58
  • Expansions with references in bash is not supported directly. You might need to re-consider your design if you are planning to do this bash Commented Jan 22, 2019 at 2:56

1 Answer 1

0

declare -n astrR="astr"

from tips here: https://unix.stackexchange.com/a/390763/30352

(answered mainly to not be left as unanswered and calling unnecessary attention from other questions needing it)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.