Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Equivalent of set -- *(DN) in sh
- X-seq: zsh-users 19753
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Eric Cook <llua@xxxxxxx>
- Subject: Re: Equivalent of set -- *(DN) in sh
- Date: Mon, 19 Jan 2015 23:05:56 +0000
- Cc: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- 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==
- In-reply-to: <54BD7ABB.5070501__36205.2317861982$1421704010$gmane$org@gmx.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>
- Mail-followup-to: Eric Cook <llua@xxxxxxx>, "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- 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>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author