From: Philippe Troin <phil@fifi.org>
To: Ray Andrews <rayandrews@eastlink.ca>, Zsh Users <zsh-users@zsh.org>
Subject: Re: better grammar with $#
Date: Sun, 30 Oct 2022 10:21:47 -0700 [thread overview]
Message-ID: <e08e38081d91649f5fc7660fe5ec4413b5df88d2.camel@fifi.org> (raw)
In-Reply-To: <a99ee704-c0b3-c0b3-7cf7-337412a83082@eastlink.ca>
[-- Attachment #1: Type: text/plain, Size: 623 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 1058 bytes --]
next prev parent reply other threads:[~2022-10-30 17:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-30 14:16 Ray Andrews
2022-10-30 17:21 ` Philippe Troin [this message]
2022-10-30 17:29 ` Roman Perepelitsa
2022-10-30 17:49 ` Ray Andrews
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e08e38081d91649f5fc7660fe5ec4413b5df88d2.camel@fifi.org \
--to=phil@fifi.org \
--cc=rayandrews@eastlink.ca \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).