Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Equivalent of set -- *(DN) in sh
- X-seq: zsh-users 19760
- From: Nikolai Weibull <now@xxxxxxx>
- To: Eric Cook <llua@xxxxxxx>, "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: Equivalent of set -- *(DN) in sh
- Date: Thu, 22 Jan 2015 08:44:40 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=+C9X7rAw6ZdmqE6oF7hBDXFMpQSXQjKwwEMxIWfR+HY=; b=x7/nK/mEZtwqPcSi/UgPhTZ5itjIPT5I22vVlliR+S7FiuQPxemxLsNjq+59FfIYcM AWtN1Lbzx9npJIbYJPeqGh9NxA5xuAUhRrHckEgowpjyq1R+nWzBjn87JK4TSD0rIHD0 nqM72C4XIPaKaSqH8QMD6O+QAJfQJWIZYynQlgoZ+p+DJU8Ro8OIl/trdwCf4LaMATPz MgAeITlMggKSXKtR/8ES8cTIjDYJhY6zNEgDcNNAxdEJp8vydMI7GH7eGRptYS5Mb4hT dN5oCJhfqPT7viMYaeUWjcvIvFdMZ9wczKS0Pby1W9l3/jau1/ieHGfdDaL2suRmdpvf Bg/g==
- In-reply-to: <20150119230556.GA4093@chaz.gmail.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>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADdV=MvMtwYczr82GeYkmVwTFCKgFcbgYS71XdnHZN_JqFqzTg@mail.gmail.com> <54BC1B8E.5080806@gmx.com> <1102431421682670@web6h.yandex.ru> <54BD7ABB.5070501__36205.2317861982$1421704010$gmane$org@gmx.com> <20150119230556.GA4093@chaz.gmail.com>
- Sender: nikolai.weibull@xxxxxxxxx
On Tue, Jan 20, 2015 at 12:05 AM, Stephane Chazelas
<stephane.chazelas@xxxxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author