From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13820 invoked by alias); 22 Jan 2015 07:51:12 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19760 Received: (qmail 20231 invoked from network); 22 Jan 2015 07:51:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 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== MIME-Version: 1.0 X-Received: by 10.194.5.37 with SMTP id p5mr281533wjp.20.1421912680617; Wed, 21 Jan 2015 23:44:40 -0800 (PST) Sender: nikolai.weibull@gmail.com In-Reply-To: <20150119230556.GA4093@chaz.gmail.com> References: <54BC1B8E.5080806@gmx.com> <1102431421682670@web6h.yandex.ru> <54BD7ABB.5070501__36205.2317861982$1421704010$gmane$org@gmx.com> <20150119230556.GA4093@chaz.gmail.com> Date: Thu, 22 Jan 2015 08:44:40 +0100 X-Google-Sender-Auth: zKi6EvGNRibUZBCBAUcMT5ZwWYI Message-ID: Subject: Re: Equivalent of set -- *(DN) in sh From: Nikolai Weibull To: Eric Cook , "zsh-users@zsh.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Jan 20, 2015 at 12:05 AM, Stephane Chazelas 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=3D" " > 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" =3D x\* && ! test -e \* && shift n=3D$# set x .[!.]* ${1+"$@"}; shift test $# -eq `expr $n + 1` && test "x$1" =3D 'x.[!.]?*' && ! test -e '.[!.]?*' && shift n=3D$# set x ..?* ${1+"$@"}; shift test $# -eq `expr $n + 1` && test =3D"x$1" =3D 'x..?*' && ! test -e '..?*' = && shift This tries to avoid using test -e (or whatever version of testing for a files existence you=E2=80=99d like to use), but also avoids using pattern= s just to test for failures to avoid unnecessary directory traversals. It also avoids messing with IFS, but perhaps that=E2=80=99s necessary? The ${1+"$@"} is to avoid an old Zsh bug, right? It also avoids set --, as that=E2=80=99s apparently not portable either.