From: Dominik Ritter <dritter03@googlemail.com>
To: p.stephenson@samsung.com
Cc: zsh-users@zsh.org
Subject: Re: Use glob patterns while reading a file
Date: Fri, 9 Nov 2018 15:37:44 +0100 [thread overview]
Message-ID: <CAJjRh0RvytSn53CxbfSUfmWzoJgfyiaBy47Wr4jHCAmJiSP2ew@mail.gmail.com> (raw)
In-Reply-To: <1541756153.3720.1.camel@samsung.com>
[-- Attachment #1: Type: text/plain, Size: 1464 bytes --]
I was hoping for a solution without externals. The cat version seems to be
slower than the other one, and I the null glob seems not to work, if
neither of the files was found..
Testing 10000 iterations of cat-glob
( repeat $ITERATIONS; do; echo $(cat < ./(a|b)(N) 2>/dev/null ) > /dev/null
2) 5,75s user 2,61s system 107% cpu 7,741 total
Testing 10000 iterations of resolve-first glob
( repeat $ITERATIONS; do; local -a files; files=(./(a|b)(N)) ; for file in
; ) 0,11s user 0,16s system 98% cpu 0,276 total
With "b" being a simple text file.
Test-Script:
#!/bin/zsh
ITERATIONS=10000
echo "Testing $ITERATIONS iterations of cat-glob"
time (repeat $ITERATIONS; do;
echo $(cat < ./(a|b)(N) 2>/dev/null ) >/dev/null 2>&1
done;)
echo "Testing $ITERATIONS iterations of resolve-first glob"
time (repeat $ITERATIONS; do;
local -a files
files=( ./(a|b)(N) )
for file in $files; do;
echo $(< ${file} ) >/dev/null
done
done;)
Am Fr., 9. Nov. 2018 um 10:36 Uhr schrieb Peter Stephenson <
p.stephenson@samsung.com>:
> On Thu, 2018-11-08 at 23:53 +0100, Dominik Ritter wrote:
> > I want to use read one of two files, regardless if it exists or not. My
> > first approach is to use the alternative glob syntax, but with no luck:
> > $(< ./(a|b)(N))
>
> That's a special syntax, expecting a single file so that it doesn't try
> to do globbing.
>
> You can get it to work with
>
> $(cat <./(a|b)(N))
>
> pws
>
>
next prev parent reply other threads:[~2018-11-09 14:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20181108225555epcas2p274de218aef35e46f189ebbfbd9d1892f@epcas2p2.samsung.com>
2018-11-08 22:53 ` Dominik Ritter
2018-11-09 9:35 ` Peter Stephenson
2018-11-09 14:37 ` Dominik Ritter [this message]
2018-11-09 16:20 ` Peter Stephenson
2018-11-10 1:21 ` Daniel Shahaf
2018-11-10 2:07 ` Bart Schaefer
2018-11-10 2:12 ` Bart Schaefer
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=CAJjRh0RvytSn53CxbfSUfmWzoJgfyiaBy47Wr4jHCAmJiSP2ew@mail.gmail.com \
--to=dritter03@googlemail.com \
--cc=p.stephenson@samsung.com \
--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).