On Saturday, April 06, 2013 06:55:09 PM Chris F.A. Johnson wrote:
> On Sat, 6 Apr 2013, Peng Yu wrote:
>
> > Bash code is not reusable in any sane way. You can't pass array names
> > to functions, for example
>
> One certainly can pass array names to functions. I have a library
> of functions that take array names as arguments:
> <http://cfajohnson.com/shell/?2013-01-08_bash_array_manipulation>.
>
> > (this is the #1 problem with writing "libraries" of bash code).
>
> I don't have any problem writing libraries of bash code; I have
> dozens of them.
>
The point is it's exceedingly difficult to do it safely. You'll never have a
really robust "library language" without some way around the dynamic scope
encapsulation problem. For example, I think this ksh93 function will never be
possible in Bash, even though this is perfectly valid Bash 4.3 code:
function f {
case $1 in
0)
typeset -a x=(I\'m an x)
f 1 x
;;
1)
typeset -n a=$2
typeset -a x=(I\'m a different x)
f 2 a x
;;
2)
typeset -n x=$2 y=$3
typeset -p x y
printf "<%s> " "${x[*]}" "${y[*]}"
echo
esac
}
f 0
# typeset -n x=x
# typeset -n y=x
# <I'm an x> <I'm a different x>
--
Dan Douglas