bug-bash
[Top][All Lists]
Advanced

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

Re: bug-bash Digest, Vol 236, Issue 8


From: Yair Lenga
Subject: Re: bug-bash Digest, Vol 236, Issue 8
Date: Wed, 6 Jul 2022 07:30:05 +0300

Hi.

I agree that the bash local variables are less than ideal (dynamic scope vs
local scope). However, we got to use what we have. In that context, using
'main' has lot of value - documentation, declarative, etc.

In my projects, we use "named" main to create reusable code (e.g. date
calculator can expose date_calc_main, which can be called as a function
after file being sourced. Ideal ? No, productive? Yes, fewer global/bugs:
yes.

One day I will be rewriting code to python :-), probably this  day will be
never. Will be interesting to look alternatives, at a different thread.
Until then, Bash is my tool.

As stated before, I will extend the errfail to the top level, as not
everyone uses bash in the same way (with respect to (not) placing logic at
the top level.


Yair




>
> Message: 5
> Date: Wed, 6 Jul 2022 13:23:14 +1000
> From: Martin D Kealey <martin@kurahaupo.gen.nz>
> To: Yair Lenga <yair.lenga@gmail.com>
> Cc: Lawrence Velázquez <vq@larryv.me>, Martin D Kealey
>         <martin@kurahaupo.gen.nz>, bug-bash <bug-bash@gnu.org>
> Subject: Re: Revisiting Error handling (errexit)
> Message-ID:
>         <CAN_U6MWyFGU53C_BZTosp074k2nyqWVdz0LMJy=
> 0dD4VDyLL5g@mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>
> On Wed, 6 Jul 2022 at 08:34, Yair Lenga <yair.lenga@gmail.com> wrote:
>
> > in general, for complex scripts, I prefer to move the ‘main’ logic into a
> > function (‘main’, ‘run’,…). This make it possible to keep clean name
> space.
> > Otherwise, all the main variables are becoming global: see below for ‘x’.
> > With many variables, it can be ugly.
> >
> > Function main () {
> >     Local x.   # x is local
> >     For x in a b ; do process $x ; done
> > }
> >
> > Vs.
> > # x is global, all function will see it.
> > For x in a b ; do process $x ; done
> >
>
> Unfortunately that's not how "local" works. In both cases the variable "x"
> is visible to (and modifiable by) everything that is called from "main"; so
> everything is inside the "main" function, "local" there is quite
> indistinguishable from true global.
>
> -Martin
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> bug-bash mailing list
> bug-bash@gnu.org
> https://lists.gnu.org/mailman/listinfo/bug-bash
>
>
> ------------------------------
>
> End of bug-bash Digest, Vol 236, Issue 8
> ****************************************
>


reply via email to

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