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

Re: triviality regarding $# counts





On Sun, Apr 14, 2024 at 10:48 Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:




% hhh=( "${(@f)iii}" )
% typeset -p hhh; typeset -p iii
typeset -a hhh=( 'abc\ndef\nghi' )
typeset iii='abc\ndef\nghi'

... newlines still there.  One element.

No newlines nowhere! You've got backslashes and n's, but nary a newline to be found. Which is the only reason (f) isn't completely mucking things up. See my last message.

BTW, just philosophically speaking, the parens are an interesting question.  Whereas I'd say that a copy is a copy is a copy:

aaa=$bbb

... so whatever bbb may happen to be, aaa will become the same.  But if aaa is a scalar, should it be promoted 'silently' ?  Seems to me the parens are explicit that aaa will become an array so I like them.  One can never be too clear as to what's happening. 

The parens are needed because of the way assignment works. At least conceptually (though the implementation may optimize), the right hand side is first expanded, and then the result of that expansion, treated as a literal value, is what gets assigned. The shell doesn't just copy the innards of the variable value from one spot in its symbol table to another; it takes a detour through first  expanding the value and then doing some subset of its normal parsing on that expanded value.


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