[Top][All Lists]

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

Re: about the local not-on-every-function-separately var issue

From: Robert Elz
Subject: Re: about the local not-on-every-function-separately var issue
Date: Mon, 22 Mar 2021 12:59:41 +0700

    Date:        Sun, 21 Mar 2021 22:42:19 -0400
    From:        Greg Wooledge <greg@wooledge.org>
    Message-ID:  <YFgECw0x7ovfliYr@wooledge.org>

  | One or more of your assumptions are wrong.
  | Bash uses "dynamic scope" when it expands variables.

Note that some other shells don't really have local variables at all, there
are only globals - the "local" command saves a copy of the state of the
variable at that point, and arranges to restore it when the current function
exits.   Lookups of variables only ever look in the global variable list.

This is a much simpler model to understand, otherwise it is hard to see how
things like "local PATH IFS OPTARG" (etc) can ever really work (variables
used or set by the shell itself).

  | Now, the big question is WHY you thought something which is not correct.
  | The most common reasons

A third is that they know some other environment, and then expect everything
to be just the same as that one, and that things should always behave the
way they're familiar with.    That's not the way the world works.
Different things are different (even different shells and how they treat 
"local", which is one reason, maybe "the" reason, why "local" isn't in the
POSIX shell standard).

I totally agree with the part about convoluted code however, I have never
been able to understand anything of what is being attempted.


reply via email to

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