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 6:58 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
>   $ typeset -mp CDPATH
> typeset -T CDPATH cdpath=(  )

That's actually a bug ... "typeset -T" doesn't take two arguments in
that format.

> ... but the same command from within a script or function gives:
>
> typeset -g -T CDPATH cdpath=(  )

The -g is because typeset -p is supposed to be outputting a command
that can be sent back through "eval".  If you were to execute that
typeset without the -g when inside a function, you would create a new
local CDPATH variable.  The -g makes sure you are still referencing
the global.

> ... and if I scan the entire output of "$ typeset -p" and look for
> 'CDPATH' I get:
>
> typeset -T CDPATH cdpath=(  )
> typeset -aT CDPATH cdpath=(  )

The first one is the (incorrect) assignment for $CDPATH.
The second one is the (correct) assignment for $cdpath.
These are "tied" variables (the -T) meaning that if you change either
one of them, the other also changes.

> ... and from within a function the '-g' is added.

See above.

> ... and while I'm whining I notice that 'set' never does anything like:
> "CDPATH cdpath", it puts them on separate lines.  Dunno, couldn't they
> have separate values?

No, they can't.  One is a colon-separated string and the other is an
array, but they always track one another.




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