[Top][All Lists]

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

Re: Revisiting Error handling (errexit)

From: Martin D Kealey
Subject: Re: Revisiting Error handling (errexit)
Date: Wed, 6 Jul 2022 13:23:14 +1000

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.


reply via email to

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