|
| From: | Léa Gris |
| Subject: | mapfile associative array shim Was: Re: [feature request] add associative array support to mapfile |
| Date: | Thu, 17 Dec 2020 16:22:38 +0100 |
| User-agent: | Telnet/1.0 [tlh] (PDP11/DEC) |
#!/usr/bin/env bash
# mapfile_assoc_shim.bash
! { mapfile -A a </dev/null;} 2>/dev/null && {
mapfile () {
local k v d=$'\n'
local -n A=${*: -1:1}
[[ ${*: -2:1} = -A ]] && {
[[ ${*:1:1} = -d ]] && d=${*:2:1}
while read -r -d "$d" k v || [[ -n $k && -n $v ]]
do A[$k]=$v
done
true
} || command mapfile "$@"
}
}
Example usage:
. mapfile_assoc_shim.bash
IFS='=' mapfile -d '' -A assoc_null < <(kv_null_stream)
--
Léa Gris
| [Prev in Thread] | Current Thread | [Next in Thread] |