Define a setvar() function for platforms using a shell unlike FreeBSD's

sh(1) for `/bin/sh' (e.g., bash(1) which lacks a setvar definition).
This is to improve portability to other Operating Systems (e.g., Linux).
This commit is contained in:
Devin Teske 2014-07-31 22:00:36 +00:00
parent e7375b6fa5
commit 4d5a468d88

View File

@ -220,6 +220,32 @@ f_have()
f_quietly type "$@"
}
# setvar $var_to_set [$value]
#
# Implement setvar for shells such as unlike FreeBSD sh(1).
#
if ! f_have setvar; then
setvar()
{
[ $# -gt 0 ] || return $SUCCESS
local __setvar_var_to_set="$1" __setvar_right="$2" __setvar_left=
case $# in
1) unset "$__setvar_var_to_set"
return $? ;;
2) : fall through ;;
*) f_err "setvar: too many arguments\n"
return $FAILURE
esac
while case "$__setvar_r" in *\'*) : ;; *) false ; esac
do
__setvar_left="$__setvar_left${__setvar_right%%\'*}'\\''"
__setvar_right="${__setvar_right#*\'}"
done
__setvar_left="$__setvar_left${__setvar_right#*\'}"
eval "$__setvar_var_to_set='$__setvar_left'"
}
fi
# f_which $anything [$var_to_set]
#
# A fast built-in replacement for syntaxes such as foo=$( which bar ). In a