Trying to simplely reference an array
declare -a arr1
declare -a arr2
declare -a arr3
currentArr=arr1
currentArr+=('abc')
currentArr=arr2
currentArr+=('qrs')
currentArr=arr1
currentArr+=('def')
When I run something like this
printf '%s\n' "${arr1[@]}" # should print abc def
I get an unbound variable error.
How do I create a pointer to an array so that I can just swap what array that pointer points at?
I did some searching but the answers I've found seem to be copying the array to another variable.
Bash I'm using: GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Options I have available: declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
Can someone please explain why this is marked a duplicate of Indirect reference to array values in bash
I don't see how that answers my question. I'm trying to modify the original arrays through the indirection.
The examples in that answer
currentArr="${arr1}[@]"
currentArr+=('abc')
Does not work.
I would like to append new values to the original array through a reference.