From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13647 invoked by alias); 19 Jan 2015 23:12:25 -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: 19753 Received: (qmail 15175 invoked from network); 19 Jan 2015 23:12:23 -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:in-reply-to :user-agent; bh=8ote0i79W+wupRrU/Nen8QTuj6tMIqo874p9r85jIUc=; b=B65oTyOF4EppKqNLNFzoSdOtz4kl3bAlkVa8jgOtatjQpurgiU97FSMsCu8I582B/C tD9qSlzANaUqj1huQLgJnSdJeqt4xSGfCe/ccuzuDUnVcxnX6ZN4VQiR/5hx5k46IfiJ X0Atihp7vEWsqlSXnt6XA+4rufONeDUpLbZEs/thgp+U1/0SbxVPiGN7Bj+mUMWM23Jo 1bsIMpMrGw6YOLis+NdTJ8KNYSWW9EmCCQ40770/OX3RvDNysdwUuIWFXWxPJmFTj84c 23T4P7ochrcS/tikjFXMo+tq8XmmSTOF+LxCkEpR6j4gDi7z+CsrDZ0sVhsDlioFOqp8 GJdw== X-Received: by 10.194.19.131 with SMTP id f3mr9020128wje.46.1421708758258; Mon, 19 Jan 2015 15:05:58 -0800 (PST) Date: Mon, 19 Jan 2015 23:05:56 +0000 From: Stephane Chazelas To: Eric Cook Cc: "zsh-users@zsh.org" Subject: Re: Equivalent of set -- *(DN) in sh Message-ID: <20150119230556.GA4093@chaz.gmail.com> Mail-Followup-To: Eric Cook , "zsh-users@zsh.org" References: <54BC1B8E.5080806@gmx.com> <1102431421682670@web6h.yandex.ru> <54BD7ABB.5070501__36205.2317861982$1421704010$gmane$org@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54BD7ABB.5070501__36205.2317861982$1421704010$gmane$org@gmx.com> User-Agent: Mutt/1.5.21 (2010-09-15) 2015-01-19 16:44:27 -0500, Eric Cook: [...] > #!/bin/sh > ${ZSH_VERSION+false} : || emulate sh > match() { > test "$#" -gt 2 && return Why not "-gt 1"? > test -e "$1" && return test -e will return false for a symlink to an inaccessible file. So you'll want a test -L "$1" as well. > return 1 > } > > set -- > for pat in '..?*' '.[!.]*' '*'; do # I moved your added pattern to where > POSIX locale would sort them. > if match $pat; then > set -- "$@" $pat Note that for that to work in the Bourne shell, IFS needs to contain space (and none of the characters in the patterns in all Bourne-like shells). 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). -- Stephane