From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Eric Cook <llua@gmx.com>
Cc: "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: Equivalent of set -- *(DN) in sh
Date: Mon, 19 Jan 2015 23:05:56 +0000 [thread overview]
Message-ID: <20150119230556.GA4093@chaz.gmail.com> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2015-01-19 23:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-18 18:28 Nikolai Weibull
2015-01-18 19:07 ` Roman Neuhauser
2015-01-18 19:43 ` Nikolai Weibull
2015-01-18 20:32 ` Roman Neuhauser
2015-01-18 19:31 ` ZyX
2015-01-18 19:46 ` Nikolai Weibull
2015-01-18 20:46 ` Eric Cook
2015-01-19 15:51 ` ZyX
2015-01-19 15:55 ` ZyX
2015-01-19 16:02 ` ZyX
2015-01-19 16:16 ` ZyX
2015-01-19 21:44 ` Eric Cook
[not found] ` <54BD7ABB.5070501__36205.2317861982$1421704010$gmane$org@gmx.com>
2015-01-19 23:05 ` Stephane Chazelas [this message]
2015-01-22 7:44 ` Nikolai Weibull
[not found] ` <CADdV=MsvuSAQMJVsr17Y7g2Nfjy95CQ007opQqv-7=RHjgjaKw__35342.9068615243$1421913204$gmane$org@mail.gmail.com>
2015-01-22 15:21 ` Stephane Chazelas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150119230556.GA4093@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=llua@gmx.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).