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

Re: Reading line by line



Stephane Chazelas wrote:
On Wed, Apr 11, 2007 at 11:52:41AM -0700, Micah Cowan wrote:
[...]
$ echo 'a   b' | read -r

zsh will preserve all whitespace between a and b, whereas other shells will condense it to a single space. POSIX states that, after splitting the fields, if there is only one variable name left in the args, all remaining fields will be assigned to that variable, with "their intervening separation", which IMO is difficult to interpret as anything other than the original separation that had been encountered.
[...]

No, you must have been confused by word splitting occuring upon
unquoted variable expansions.

Perhaps. I could've sworn I'd quoted it... but now that I think about it, I probably used OP's example, which has it unquoted.

echo 'a  b' | read a
echo "$a"

outputs "a  b"

That's what POSIX requires and that's how zsh behaves when
in POSIX emulation.

Right; I was talking about bash, dash and ksh behavior not being compliant, not zsh. But, if I did indeed leave it unquoted, that would explain the difference, since zsh, by default, does not field-split unquoted variables.

Note that word splitting is not the only thing performed by
POSIX shells upon variable expansion, there's also filename
generation. That's why one should *NEVER* leave variables
unquoted in POSIX scripts.

Agreed, absolutely. Well... s/*NEVER*/only when you know that word expansion is actually what you really want/

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/



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