nested array 2

This commit is contained in:
pvincent
2026-07-19 18:27:26 +04:00
parent 2c5e42feac
commit 429b97619c
+8 -16
View File
@@ -9,18 +9,12 @@
# declare -p ref1 # declare -p ref1
# for i in "${ref1[@]}"; do echo "-> $i"; done # for i in "${ref1[@]}"; do echo "-> $i"; done
function sub {
[[ ! -v index ]] && index=0
declare -ga "$1"
declare -n ref2="$1"
ref2+=($((++index)))
ref2+=($((++index)))
}
function build { function build {
array_name="$1" ref_name="$1"
sub "$array_name" [[ -v nested_count ]] && ((++nested_count)) || nested_count=1
# declare -n ref=$array_name nested_name="_nested_$nested_count"
declare -ga "$nested_name"=\(\)
declare -gn "$ref_name"="$nested_name"
} }
function array_inspect { function array_inspect {
@@ -31,8 +25,6 @@ function array_inspect {
} }
build mine1 build mine1
build mine2 array_inspect mine1
mine1+=("A" "B C D" "E")
declare -n other=mine1 array_inspect mine1
array_inspect other
array_inspect mine2