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

Re: What is the '+' option of the 'typeset' builtin supposed to do?



On Sun, Sep 13, 2026 at 8:55 AM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> If ‘+’ appears by itself in a separate word as the last option

This is something inherited / extended from ksh, so in part this
should follow the implementation there.

The most significant bit is this:

> 'typeset + str=abc int=1+2' prints nothing and assigns the parameters => ???

That's what ksh does.  Assignments always "win".  Worth documenting.

> ... the effect of ‘+’ is as if all attribute flags which precede it were given with a ‘+’ prefix. For example, ‘typeset -U +’ is equivalent to ‘typeset +U’ ...

This is dependent on an earlier bit of doc:
     If no NAME is present, the names and values of all parameters are
     printed.  In this case the attribute flags restrict the display to
     only those parameters that have the specified attributes, and using
     '+' rather than '-' to introduce the flag suppresses printing of
     the values of parameters when there is no parameter name.

So `typeset -U +' and `typeset -U + foo' are distinct and the latter
is not the same as `typeset +U foo' despite what's implied by
combining the standalone-'+' paragraph with only the "rather than"
clause of the '+flag' paragraph.

Further, `typeset +U + foo' ignores the standalone '+' entirely and
removes the uniqueness attribute from foo, which is not documented
clearly at all and probably represents an unintentional edge case that
also explains your question about `-i +'.

> 'typeset +' prints the name and type of all parameters => ok

Ksh prints only the names of all parameters, so this is an extension.

> 'typeset -i +' prints the name of all integer parameters => ok

This mirrors ksh exactly.

> 'typeset -t +' prints the name of all tagged parameters => ok

Presumably correct.

> 'typeset -i -t +' prints the name of all integer parameters => okish
> Why not print only tagged integer parameters?

This probably comes down to an oversight in how printparamnode() is
implemented.  Tagging has always been a bit of a non-feature feature.

> 'typeset + str int' prints the name and value of the listed parameters => ok
> 'typeset -i + str int' prints nothing but turns the listed parameters into integers => KO
> Why does that change the type of the parameters?

See above.  I've no strong feelings about whether this should be
changed or merely properly documented.  Anyone?

> Shouldn't this just print the name and value of either all the listed parameters or of just the ones that are integers?

If it IS changed, I would say "just the ones that are integers" ...
although that conflicts with the behavior of `typeset -i -p NAME...',
so uncertain.

> 'typeset + undef' prints nothing and creates a string parameter => KO
> Why does this create a parameter?

This probably an accidental effect of the "assignments always win" behavior.




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