[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] starting a central bash script repository

From: Dan Douglas
Subject: Re: [Help-bash] starting a central bash script repository
Date: Sun, 07 Apr 2013 14:37:57 -0500
User-agent: KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; )

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:
>    <>.
> > (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
            typeset -a x=(I\'m an x)
            f 1 x
            typeset -n a=$2
            typeset -a x=(I\'m a different x)
            f 2 a x
            typeset -n x=$2 y=$3
            typeset -p x y
            printf "<%s> " "${x[*]}" "${y[*]}"

f 0

# typeset -n x=x
# typeset -n y=x
# <I'm an x> <I'm a different x>

Dan Douglas

reply via email to

[Prev in Thread] Current Thread [Next in Thread]