From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21281 invoked by alias); 22 Jan 2015 15:21:47 -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: 19765 Received: (qmail 16975 invoked from network); 22 Jan 2015 15:21:44 -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.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=jb2sFjdQcYjptCHdakVKliAZ2xvXi6VurDzO5/epaz4=; b=tedyB0XQQJwrZhRVGSHdE3oXC7ZKyPHy8VdIgD0sOhz7bzidDI3gmHO1WllPURqJBl x/6F3LgdYEJfgPl+apvhNKMM+70RT5tJ1DE+yl2SuJtx0FTLJF1F++52uHyJVDXcphfY xOOhAJpCnGn7rnW1V5pqTcXBx+zPulgHMIsF9YuYQROQ3tyKJ6xABke52vLUk1SQw6/U 8T5FafoNXvYlggZbAezELKsd887lQ4JA8SJwLpDYjf2Hhs4yBBs9/MIfqidw66/3Ld8e jtu+7J77hQTeSrmC/00cKewRyv7wcH3vNcn/eO3Etgt+mop7395lB7/bXAtcoM3dAFac wsQQ== X-Received: by 10.180.198.51 with SMTP id iz19mr6024720wic.65.1421940101765; Thu, 22 Jan 2015 07:21:41 -0800 (PST) Date: Thu, 22 Jan 2015 15:21:40 +0000 From: Stephane Chazelas To: Nikolai Weibull Cc: Eric Cook , "zsh-users@zsh.org" Subject: Re: Equivalent of set -- *(DN) in sh Message-ID: <20150122152139.GB8163@chaz.gmail.com> Mail-Followup-To: Nikolai Weibull , Eric Cook , "zsh-users@zsh.org" References: <54BC1B8E.5080806@gmx.com> <1102431421682670@web6h.yandex.ru> <54BD7ABB.5070501__36205.2317861982$1421704010$gmane$org@gmx.com> <20150119230556.GA4093@chaz.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) 2015-01-22 08:44:40 +0100, Nikolai Weibull: [...] > 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) Well, it doesn't try very hard does it ;-) ? Remember you need test -e || test -L (or test -h on some old systems). > but also avoids using patterns > just to test for failures to avoid unnecessary directory traversals. The directory content will be in cache after the first `set x *`. Forking and exeuting some exprs is probably going to be worse in most cases. > It also avoids messing with IFS, but perhaps that’s necessary? Well, yes "$@" in the Bourne shell relies on it containing space and you're leaving a number of variables and command substitutions unquoted. Note that "case" has far fewer problems than "test". > > The ${1+"$@"} is to avoid an old Zsh bug, right? No, that's the other way round. ${1+"$@"} is to work around problems with the Bourne shell (at least those where that has not been fixed (where "$@" expands to one empty argument when $# is 0)). zsh is the one that had problems with ${1+"$@"} (not "$@"), not really a bug, but down to how parameter expansion nested. Which is why you see things like: test -z "$ZSH_VERSION" || alias -g '${1+"$@"}="$@"' > It also avoids set --, as that’s apparently not portable either. According to http://www.in-ulm.de/~mascheck/bourne/, -- was added to the Bourne shell at the same time as [!...], so that would suggest that if you want to account for those very old systems, you can't use [!...] either. Note that old Bourne shells didn't support characters with the 8th bit set either. -- Stephane