|
|
@ -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" |
|
|
|
|
|
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 { |
|
|
function array_inspect { |
|
|
@ -31,8 +25,6 @@ function array_inspect { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
build mine1 |
|
|
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 |