[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Function printing arrays
From: |
hancooper |
Subject: |
Function printing arrays |
Date: |
Thu, 26 Aug 2021 00:10:12 +0000 |
I have the following function that prints associative arrays.with key and value.
Would like to extend it to print normal arrays (non-associative - without keys)
as well.
I call it using pfa "TITLE" assoc_array
pfa ()
{
local _title="$1"
local -n asta="$2"
local ky="" i=0
local sga=$(tput setaf 118)
local sgr=$(tput sgr0)
echo -n $sga ; printf '\n%s\n' "$_title" ; echo -n $sgr
printf '%s\n' "nelm: ${#asta[@]} \${#asta[@]}"
printf '%s%s%s\n' $sga "---" $sgr
i=0
for ky in "${!asta[@]}"; do
((i+=1))
printf 'Key: %s\n' "$ky"
printf 'Val: %s\n' "${asta[$ky]}"
if (( i == ${#asc[@]} )); then
printf '%s%b%s\n\n' "$sga" '-\u2625-' "$sgr"
else
printf '%s%s%s\n' "$sga" '---' "$sgr"
fi
done
}
- Function printing arrays,
hancooper <=