From 429b97619c4bb670df13af56af4a9834175ec82b Mon Sep 17 00:00:00 2001 From: pvincent Date: Sun, 19 Jul 2026 18:27:26 +0400 Subject: [PATCH] nested array 2 --- test/associative.test.bash | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/test/associative.test.bash b/test/associative.test.bash index 78091d9..cdd500e 100755 --- a/test/associative.test.bash +++ b/test/associative.test.bash @@ -9,18 +9,12 @@ # declare -p ref1 # 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 { - array_name="$1" - sub "$array_name" - # declare -n ref=$array_name + ref_name="$1" + [[ -v nested_count ]] && ((++nested_count)) || nested_count=1 + nested_name="_nested_$nested_count" + declare -ga "$nested_name"=\(\) + declare -gn "$ref_name"="$nested_name" } function array_inspect { @@ -31,8 +25,6 @@ function array_inspect { } build mine1 -build mine2 - -declare -n other=mine1 -array_inspect other -array_inspect mine2 +array_inspect mine1 +mine1+=("A" "B C D" "E") +array_inspect mine1