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

Re: better grammar with $#



On Sun, 2022-10-30 at 07:16 -0700, Ray Andrews wrote:


    output=$( eval "$@" )  # Input here is a 'find' command outputting a list of files.
    tmp=( ${(f)output} )   # Count lines not characters.
    linecount=$#tmp

... it seems clumsy to create 'tmp' just to count lines, can that be a bit more streamlined?  And is it lines or words there?  The output is filenames so words=lines in this case but maybe not in other cases so I'd like to be sure to have a count of lines.  Easy to get one's splitting wrong.


How about:
linecount=${#${(f)"$(eval "$@")"}}

Phil.



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