Freddy Vulto wrote:
# Param: $1 �variable name to return value to
# Public library function
blackbox() {
local __1
_blackbox __1
[[ $1 == __1 ]]&& echo "ERROR: variable name conflicts"\
"with local variable: $1"
printf -v $1 %s "$__1"
}
# Param: $1 �variable name to return value to
# Public library function
blackbox() {
[[ "$1" =~ [_[:alpha:]][_[:alnum:]]* ]] || die # TODO: error instead
if [ $1 == "__1" ]; then
local __2
_blackbox __2
printf -v $1 %s "$__2"
else
local __1
_blackbox __1
printf -v $1 %s "$__1"
fi
}
Wouldn't that avoid having variable names that can't be used?
It should be possible to place this code in a generic wrapper such that
you can do:
blackbox1() { call_varref _blackbox1 "$@"; }
blackbox2() { call_varref _blackbox2 "$@"; }
This requires, of course, that only one variable is 'passed by-ref' and
is at a consistent position (though you could easily add a parameter
specifying what position). How to do this is left as an exercise for the
reader :-).
--
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
--
Oops. -- Shannon Foraker (David Weber, Ashes of Victory)