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

Re: trapped in bash



On Fri, Dec 16, 2016 at 9:33 AM, Ray Andrews <rayandrews@xxxxxxxxxxx>
wrote:
>
> BTW:
>
>     _array=( ${(f)_variable} )
>     _count=$#_array   # Count the number of lines.
>
> Can that be simplified? I don't need the _array, just the _count. Of
> course there are any number of utilities to count lines, but I mean the
> simplest zsh way, although the above is nicely self-explanatory


_count=${#${(f)_variable}}

This will remove the need for the variable _array. One caution, if your
not already aware, (f) removes blank lines, so they won't show up in
the count.

Hope this helps,

Jim


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