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

Re: Counting characters in command output?





On Tue, Feb 13, 2024 at 3:41 PM Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
On Tue, 13 Feb 2024 at 21:39, Mark J. Reed <markjreed@xxxxxxxxx> wrote:
I thought this would give me the length of the string, but it seems to be counting words instead:

     zsh% echo ${#$(echo hello)}
     1

Is this a bug? I thought I'd need a modifier flag to treat output as an array and give me  a word count, while character count would be the default.

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!

 
--
Mark J. Reed <markjreed@xxxxxxxxx>


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