help-bash
[Top][All Lists]
Advanced

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

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


From: Peng Yu
Subject: Re: [Help-bash] starting a central bash script repository
Date: Sun, 7 Apr 2013 17:08:38 -0500

On Sun, Apr 7, 2013 at 2:37 PM, Dan Douglas <address@hidden> wrote:
> 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>

I think that my original point is to reuse bash scripts. But it seems
that topics are skewed toward reusing bash functions (safely), which I
think is a much more difficult topic.

Given the current limitations (or merit if you consider it does what
bash should do) of bash, the only useful question is how to reuse bash
scripts (at the scale of cpan or pypi), which can be wrappers of
scripts written in other languages, rather than bash functions. Bash
is good at gluing things. If one really need to reuse a lot of bash
functions, why not just reuse the code or functions in perl, python,
etc.

-- 
Regards,
Peng



reply via email to

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