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

Re: var=$( typeset "$1" ) ... not within a function.



On Thu, Oct 20, 2022 at 9:16 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
>
> On 2022-10-20 11:44, Roman Perepelitsa wrote:
> > USER` behaves differently depending on whether typeset_silent is set
> > or not. You tested `typeset USER` in an environment where this option
> > is set and then in another environment where it's unset, and got
> > different results.
>
> file 'test':
>
> function ii ()
>
> {
> setopt typeset_silent
> var=$(typeset USER)
> print set in function $var
>
> unsetopt typeset_silent
> var=$(typeset USER)
> print unset in function $var
> }
> setopt typeset_silent
> var=$(typeset USER)
> print set in script $var
>
> unsetopt typeset_silent
> var=$(typeset USER)
> print unset in script $var
>
> . test; ii
> set in script
> unset in script USER=root
> set in function
> unset in function
>
> ... confused.

Oh, I see what you mean. I confused you, sorry.

typeset_silent kicks in only when you do `typeset foo` and there is
already `foo` in scope. Here, when have `typeset USER` in a function,
there is no `USER` in scope, so a new parameter is defined.

I cannot offer a solution because I don't know what you are trying to
achieve. No small change will make this code look reasonable.

Roman.




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