Date: Sun, 21 Mar 2021 22:42:19 -0400 From: Greg Wooledge <g...@wooledge.org> Message-ID: <yfgecw0x7ovfl...@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. kre