Replace associative array w/ variable indirection

Bash 3 doesn't have associative arrays. Use variable indirection to
save various checksum algorithm support results. `printf -v` can save
the output to a variable, whose name is itself stored in a variable
This commit is contained in:
Jason Karns 2016-01-18 21:28:36 -05:00
parent 14750a0b93
commit 8738d1935c

View file

@ -246,10 +246,14 @@ compute_md5() {
fi fi
} }
declare -a HAS_CHECKSUM_SUPPORT
has_checksum_support() { has_checksum_support() {
local checksum_command="$1" local checksum_command="$1"
return ${HAS_CHECKSUM_SUPPORT[$checksum_command]:=$(echo test | "$checksum_command" >/dev/null; echo $?)} local has_checksum_var="HAS_CHECKSUM_SUPPORT_${checksum_command}"
if [ -z "${!has_checksum_var+defined}" ]; then
printf -v "$has_checksum_var" "$(echo test | "$checksum_command" >/dev/null; echo $?)"
fi
return "${!has_checksum_var}"
} }
verify_checksum() { verify_checksum() {