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

Re: Use glob patterns while reading a file



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