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

Re: Counting characters in command output?



I think splitting vs not splitting could go either way; there are pros and cons to each default, and as long as there's a mechanism to do the other one, it's workable. 

But I do think it's a bit counterintuitive that parameter expansion is not split by default, while command expansion is. I would in general have expected foo $(bar)  to behave identically to baz=$(bar); foo $baz.  In bash or ksh, that's true (probably absent some edge cases I'm not thinking of), but not in zsh. Specifically, I would have thought you'd need ${=$(...)} to get the word spitting that you instead get by default.

On Wed, Feb 14, 2024 at 1:49 AM Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
On Wed, Feb 14, 2024 at 1:46 AM Mark J. Reed <markjreed@xxxxxxxxx> wrote:
>
> On Tue, Feb 13, 2024 at 3:41 PM Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
>>
>> Process substitution gives you an array. Quote it if you need a scalar.
>
> You mean command substitution, but thanks! It wouldn't have
> occurred to me to put quotes around it to change what the `#` was
> counting!

Right, command substitution. In my opinion, it's unfortunate that
command substitution in zsh splits on IFS by default. I wish this
wasn't the case. It's not even common that one wants to split command
output into words. Lines -- perhaps, but not words. So the default
behavior in this case is rarely what is desired and has to be actively
turned off.

Roman.


--
Mark J. Reed <markjreed@xxxxxxxxx>


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