[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: Chris F.A. Johnson
Subject: Re: [Help-bash] starting a central bash script repository
Date: Sun, 7 Apr 2013 18:15:41 -0400 (EDT)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Sun, 7 Apr 2013, Peng Yu wrote:

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:

(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>

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,

   Why not reuse them in bash?

   Chris F.A. Johnson, <>
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

reply via email to

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