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

Re: Assign to outer parameter from function called by zargs



On Tue, Mar 28, 2023 at 6:25 PM Eric Nielsen <ericbn@xxxxxxx> wrote:
>
> assign_outer() {
>   outer=${outer}${1}
> }
> () {
>   autoload -Uz zargs
>   local outer=a
>   zargs -n 1 -P 0 -- b c -- assign_outer
>   print ${outer}
> }
>
> results in:
> a
> and I was expecting to get:
> abc

assign_outer runs in a subshell, so it cannot modify the parameters of
the parent shell. It's similar to this:

    outer=a
    ( outer+=b ) &
    ( outer+=c ) &
    wait
    print $outer  # still "a"

Roman.




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