nested array 1
This commit is contained in:
+2
-2
@@ -57,8 +57,8 @@ function _style_fg {
|
||||
function _style_bg {
|
||||
if [[ -n "$1" ]]; then
|
||||
[[ -v BG_COLORS[$1] ]] && echo "${BG_COLORS[$1]}" && return
|
||||
>&2 echo "unknown BG value: $1"
|
||||
false
|
||||
>&2 echo "unknown BG value: $1" && return 1
|
||||
# false
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
+29
-4
@@ -2,7 +2,32 @@
|
||||
|
||||
. "$MIAOU_BASH_DIR/lib/ansi.bash"
|
||||
|
||||
content=$(BG=RED FG=BLACK style_ansi "SUBSHELL TERM")
|
||||
content=$(PADDING=2 BG=RED style_padding "$content")
|
||||
detail=$(PADDING=1 style_padding "blabla")
|
||||
PADDING=2 BG=RED FG=BLACK style_block "$content$detail"
|
||||
TYPE='SUBSHELL TERM'
|
||||
PAYLOAD='blabla'
|
||||
|
||||
stack_sources=('file.bash' './lib/utility.bash' 'file.bash')
|
||||
stack_lines=(18 56 12)
|
||||
stack_functions=('f2' 'f1' '<main>')
|
||||
|
||||
BG=RED
|
||||
FG=BLACK
|
||||
PADDING=2
|
||||
content=$(style_ansi "${TYPE}")
|
||||
content=$(style_padding "$content")
|
||||
detail=$(BG=BLACK style_padding "${PAYLOAD}")
|
||||
style_block "$content$detail"
|
||||
|
||||
# block continuation
|
||||
tput sc
|
||||
tput cuu 1
|
||||
style_ansi "\t╦"
|
||||
tput rc
|
||||
|
||||
style_ansi "\t║"
|
||||
echo
|
||||
|
||||
for i in "${!stack_sources[@]}"; do
|
||||
style_ansi "\t╟"
|
||||
# echo "─⟶ ${sources[$i]}:${lines[$i]} in ${functions[$i]}"
|
||||
printf "─⟶ %40s\t%s\n" "${stack_sources[$i]}:${stack_lines[$i]}" "${stack_functions[$i]}"
|
||||
done
|
||||
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/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 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
|
||||
}
|
||||
|
||||
function array_inspect {
|
||||
declare -n ref="$1"
|
||||
echo "array '$1' contains ${#ref[@]} elements"
|
||||
for i in "${ref[@]}"; do echo "-> $i"; done
|
||||
echo -----
|
||||
}
|
||||
|
||||
build mine1
|
||||
build mine2
|
||||
|
||||
array_inspect mine1
|
||||
array_inspect mine2
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env miaou-bash
|
||||
|
||||
ArrayOfArray_1=("Alan" "24")
|
||||
ArrayOfArray_2=("Walker" "31")
|
||||
MainArray=()
|
||||
|
||||
array_count=0
|
||||
|
||||
array_count=$(( array_count + 1 ))
|
||||
array_name="array_$array_count"
|
||||
declare -a "$array_name"
|
||||
declare -n ref="$array_name"
|
||||
ref+=("Bernard")
|
||||
ref+=(46)
|
||||
MainArray+=(ref[@])
|
||||
|
||||
array_count=$(( array_count + 1 ))
|
||||
array_name="array_$(( array_count + 1 ))"
|
||||
declare -a "$array_name"
|
||||
declare -n ref2="$array_name"
|
||||
ref2+=("Ferland")
|
||||
ref2+=(17)
|
||||
MainArray+=(ref2[@])
|
||||
|
||||
|
||||
|
||||
for sub_array in "${MainArray[@]}"; do
|
||||
elements=("${!sub_array}") # Get the elements of the sub-array
|
||||
name=${elements[0]}
|
||||
age=${elements[1]}
|
||||
echo "${name,,} $age"
|
||||
done
|
||||
Reference in New Issue
Block a user