[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Local variables for nested function calls
From: |
eduardo-chibas |
Subject: |
Local variables for nested function calls |
Date: |
Wed, 28 Jul 2021 18:55:19 +0200 |
> Sent: Thursday, July 29, 2021 at 3:07 AM
> From: "Greg Wooledge" <greg@wooledge.org>
> To: help-bash@gnu.org
> Subject: Re: Local variables for nested function calls
>
> On Wed, Jul 28, 2021 at 04:53:01PM +0200, eduardo-chibas@caramail.com wrote:
> > I have a function `pregion` that is called from another function `plist`.
> > If `plist` sets the variable `fdir` using `local fdir=${dpath:-$PWD}`
> > but in `pregion` the variable `fdir` is used without being defined as
> > local, it then considers `fdir` to be assigned to the value set by the
> > parent function.
>
> Correct. This is called "dynamic scope".
>
> > Everything gets very complicated. I want to ask how to properly handle
> > things so that they do not come to bite you later on.
>
> However you feel is correct for your script. You haven't actually
> stated a problem yet, or asked a question specific enough that we
> can give advice.
>
> > Furthermore, is it still acceptable to use `${parameter:-word}` and
> > `${parameter:=word}` these days ? Rather than simply using
> > `[[ $fdir ]] || fdir=this` or `[[ -v fdir ]] || fdir=that`.
>
> You can use whatever you feel is best. I dislike : "${foo:=bar}" but
> that's just me.
>
> local foo=${1:-default} is far more readable. I don't object to that.
>
Some object to this one,
local foo=${foo:-default}
- Local variables for nested function calls, eduardo-chibas, 2021/07/28
- Re: Local variables for nested function calls, Greg Wooledge, 2021/07/28
- Re: Local variables for nested function calls, eduardo-chibas, 2021/07/28
- Local variables for nested function calls,
eduardo-chibas <=
- Re: Local variables for nested function calls, Greg Wooledge, 2021/07/28
- Local variables for nested function calls, eduardo-chibas, 2021/07/28
- Re: Local variables for nested function calls, Greg Wooledge, 2021/07/28
- Local variables for nested function calls, eduardo-chibas, 2021/07/28
- Local variables for nested function calls, eduardo-chibas, 2021/07/28
- Local variables for nested function calls, eduardo-chibas, 2021/07/28
- Local variables for nested function calls, eduardo-chibas, 2021/07/28
- Re: Local variables for nested function calls, Alex fxmbsw7 Ratchev, 2021/07/28
- Local variables for nested function calls, eduardo-chibas, 2021/07/28
- Are you trolling us?, Greg Wooledge, 2021/07/28