[Top][All Lists]

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

Re: Local variables for nested function calls

From: eduardo-chibas
Subject: Re: Local variables for nested function calls
Date: Wed, 28 Jul 2021 18:52:40 +0200

> Sent: Thursday, July 29, 2021 at 3:07 AM
> From: "Greg Wooledge" <>
> To:
> Subject: Re: Local variables for nested function calls
> On Wed, Jul 28, 2021 at 04:53:01PM +0200, 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.

I agree with the last command, as I need the variable local anyway.

reply via email to

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