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 8:39 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2022-10-20 10:54, Roman Perepelitsa wrote:
> > The function is a red herring. If you run `unsetopt typeset_silent` in
> > the function or before invoking it, you'll see the same behavior as
> > you see in the script. If you read the description of this option,
> > you'll immediately see that everything works as expected. This option
> > controls `typeset` in exactly the way you are observing.
>
> But wouldn't my shell settings be inherited by the function?  It may be
> all as wanted, but it seems anomalous.  Why this special handling for
> typeset?  I can see that if you are setting or changing something, then
> the effect within a function will be different so various protections
> might be in order, but the simple display of an environment variable ...
> it seems strange.

There is no special handling of typeset within functions. `typeset
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. This is expected. If you want `typeset USER` to
print, make sure to unset typeset_silent beforehand. However, what you
are doing is so bizarre that you should probably rewrite that code. I
would offer an alternative but I have no guess as to what you might be
trying to achieve.

Roman.




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