MIAOU-BASH is a collection of settings and helpers for leveraging BASH. Developer-friendly, it may be used as solo package with or without the miaou project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
724 B

#!/usr/bin/env miaou-bash
# declare -a normal
# declare -n ref1=normal
# ref1+=(5)
# ref1+=(9)
# ref1+=(10)
# declare -p normal
# declare -p ref1
# for i in "${ref1[@]}"; do echo "-> $i"; done
function array_new {
ref_name="$1"
shift
[[ -v nested_count ]] && ((++nested_count)) || nested_count=1
nested_name="_nested_$nested_count"
declare -ga "$nested_name"
declare -gn "$ref_name"="$nested_name"
declare -n internal="$nested_name"
internal+=("$@")
}
function array_inspect {
declare -n ref="$1"
echo "array '$1' contains ${#ref[@]} elements"
for i in "${ref[@]}"; do echo "-> $i"; done
echo -----
}
array_new mine1 'toto est fluo' 0
array_inspect mine1
mine1+=("B C D" "E")
array_inspect mine1