Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Use glob patterns while reading a file
- X-seq: zsh-users 23749
- From: Dominik Ritter <dritter03@xxxxxxxxxxxxxx>
- To: p.stephenson@xxxxxxxxxxx
- Subject: Re: Use glob patterns while reading a file
- Date: Fri, 9 Nov 2018 15:37:44 +0100
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZDfqj5TMPEDb+GL/80dCV/u4miyRu3EkMWEQlePEtUA=; b=I6kq2aOcUgV7FOsiep2yHIwdvLzJDpTrUAcDuf4dtgLdvB/wDdKu6UEuK1CqjVgORK CAWoI85OwCyHUp/4h9Y/OqXtGpdRr+B2FYOb6BnVAXTvvitHPSkVoGCpVhLngKzMUISa cnCcdEIhWLeclZZK07nDHcndUmy/i5cVxWr+OBcs/trob/PakAx05vswHrcCpedmdmPC hbfemdCiCKCXm6cYQEqDvktwyeNo1n9kdWUohMGNbPtz7uvt15OrVc9REAmNE4to+wgu Oiy+2qMmag4Zy4yX9xl5+qL5IWmULwPOQaLMk8fJG2FtQFCLzIjwA5/1bbWfbtIf4UmF 5N8w==
- In-reply-to: <1541756153.3720.1.camel@samsung.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CGME20181108225555epcas2p274de218aef35e46f189ebbfbd9d1892f@epcas2p2.samsung.com> <CAJjRh0SROuSoc4f+3bqLNsc+iASx7MRULrNWqdPjK+MKFHys7A@mail.gmail.com> <1541756153.3720.1.camel@samsung.com>
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@xxxxxxxxxxx>:
> 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
>
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author