From: Nikolai Weibull <now@disu.se>
To: Eric Cook <llua@gmx.com>, "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: Equivalent of set -- *(DN) in sh
Date: Thu, 22 Jan 2015 08:44:40 +0100 [thread overview]
Message-ID: <CADdV=MsvuSAQMJVsr17Y7g2Nfjy95CQ007opQqv-7=RHjgjaKw@mail.gmail.com> (raw)
In-Reply-To: <20150119230556.GA4093@chaz.gmail.com>
On Tue, Jan 20, 2015 at 12:05 AM, Stephane Chazelas
<stephane.chazelas@gmail.com> wrote:
> Another approach that only relies on reading the directory
> contents (not "stat"ing the files):
>
> set -- [*] *
> case $1$2 in
> '[*]*') shift 2;;
> *) shift
> esac
> IFS=" "
> set -- .[.]?* ${1+"$@"}
> case $1 in '.[.]?*') shift; esac
> set -- .[[]'!.]?*' .[!.]?* ${1+"$@"}
> case $1$2 in
> '.[[]!.]?*.[!.]?*') shift 2;;
> *) shift
> esac
>
> (won't give the same order as *(ND) either).
How about
set x *; shift
test $# -eq 1 && test "x$1" = x\* && ! test -e \* && shift
n=$#
set x .[!.]* ${1+"$@"}; shift
test $# -eq `expr $n + 1` && test "x$1" = 'x.[!.]?*' && ! test -e
'.[!.]?*' && shift
n=$#
set x ..?* ${1+"$@"}; shift
test $# -eq `expr $n + 1` && test ="x$1" = 'x..?*' && ! test -e '..?*' && shift
This tries to avoid using test -e (or whatever version of testing for
a files existence you’d like to use), but also avoids using patterns
just to test for failures to avoid unnecessary directory traversals.
It also avoids messing with IFS, but perhaps that’s necessary?
The ${1+"$@"} is to avoid an old Zsh bug, right?
It also avoids set --, as that’s apparently not portable either.
next prev parent reply other threads:[~2015-01-22 7:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-18 18:28 Nikolai Weibull
2015-01-18 19:07 ` Roman Neuhauser
2015-01-18 19:43 ` Nikolai Weibull
2015-01-18 20:32 ` Roman Neuhauser
2015-01-18 19:31 ` ZyX
2015-01-18 19:46 ` Nikolai Weibull
2015-01-18 20:46 ` Eric Cook
2015-01-19 15:51 ` ZyX
2015-01-19 15:55 ` ZyX
2015-01-19 16:02 ` ZyX
2015-01-19 16:16 ` ZyX
2015-01-19 21:44 ` Eric Cook
[not found] ` <54BD7ABB.5070501__36205.2317861982$1421704010$gmane$org@gmx.com>
2015-01-19 23:05 ` Stephane Chazelas
2015-01-22 7:44 ` Nikolai Weibull [this message]
[not found] ` <CADdV=MsvuSAQMJVsr17Y7g2Nfjy95CQ007opQqv-7=RHjgjaKw__35342.9068615243$1421913204$gmane$org@mail.gmail.com>
2015-01-22 15:21 ` Stephane Chazelas
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='CADdV=MsvuSAQMJVsr17Y7g2Nfjy95CQ007opQqv-7=RHjgjaKw@mail.gmail.com' \
--to=now@disu.se \
--cc=llua@gmx.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).