Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: limit scope of variable



I think you can prefix the called function with IFS=$OLDIFS.  I.e.:

IFS=$OLDIFS Rays_function

E.g.:

function a {
; echo $a
; }
: ~ Tue 3 16:37; a=foo
: ~ Tue 3 16:37; a
foo
: ~ Tue 3 16:37; a=bar a
bar
: ~ Tue 3 16:37; a
foo



On Tue, Aug 3, 2021 at 4:15 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
I have a function that requires this:

     local IFS=$'\n'

... but the function calls other functions in which I need to protect
$IFS from that change.  Can I limit the scope?  As it is I'm laboring it
with this:

In the calling function:

      local OLDIFS="$IFS"
      local IFS=$'\n'

In the called function:

     IFS=$OLDIFS

     code ...
     code ...

     IFS=$'\n'
     return

... there's got to be a more streamlined way.




Messages sorted by: Reverse Date, Date, Thread, Author