zsh-users
 help / color / mirror / code / Atom feed
From: Eric Cook <llua@gmx.com>
To: "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: Equivalent of set -- *(DN) in sh
Date: Mon, 19 Jan 2015 16:44:27 -0500	[thread overview]
Message-ID: <54BD7ABB.5070501@gmx.com> (raw)
In-Reply-To: <1102431421682670@web6h.yandex.ru>

[-- Attachment #1: Type: text/plain, Size: 2490 bytes --]

On 01/19/2015 10:51 AM, ZyX wrote:
> `..foo` is a valid name, but it is being excluded. You need to add `'.??*'` to the list of patterns.
Nice catch.

On 01/19/2015 11:02 AM, ZyX wrote:
>
> And you must replace `[^.]` with `[!.]`. mksh does not support `[^]` and treats this as `[\^.]`, but other shells I have (dash, ksh, zsh (in sh emulation mode), bash, busybox ash) are fine with both `[!.]` and `[^.]`.
and again.

On 01/19/2015 11:16 AM, ZyX wrote:
>     emulate -L sh &>/dev/null
While this is just an test, it should be pointed out that `&>' is also
not defined nor does the same thing in all of the shells you tried. The
correct way being `>/dev/null 2>&1'.

On 01/19/2015 11:16 AM, ZyX wrote:
> Also note that if you need *full* equivalent of *(DN) you need to do something with ordering.
That depends on the user's locale, my LC_COLLATE was set to POSIX during
my tests and each shell sorted the files the same.
Setting LC_COLLATE to en_US.UTF-8 does give me the behavior you
mentioned. I don't think there is a correct way to account for that.

With:

#!/bin/sh
${ZSH_VERSION+false} : || emulate sh
match() {
  test "$#" -gt 2 && return
  test -e "$1"    && return
  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
  fi
done
unset pat

test "$#" -gt 0 && printf '%s ' "$@"

% LC_COLLATE=POSIX
% printf '%s ' *(DN) > ../zshdn--set.log
% for sh in dash ksh mksh zsh bash bb; do $sh ../foo >../$sh--set.log; done
% md5sum ../*--set.log
99970f198535e5fe62aeec1a13ebc639  ../bash--set.log
99970f198535e5fe62aeec1a13ebc639  ../bb--set.log
99970f198535e5fe62aeec1a13ebc639  ../dash--set.log
99970f198535e5fe62aeec1a13ebc639  ../ksh--set.log
99970f198535e5fe62aeec1a13ebc639  ../mksh--set.log
99970f198535e5fe62aeec1a13ebc639  ../zsh--set.log
99970f198535e5fe62aeec1a13ebc639  ../zshdn--set.log


% LC_COLLATE=en_US.UTF-8
% printf '%s ' *(DN) > ../zshdn--set.log
% for sh in dash ksh mksh zsh bash bb; do $sh ../foo >../$sh--set.log; done
% md5sum ../*--set.log
28583c502cf605e105f794a37e1648da  ../bash--set.log
28583c502cf605e105f794a37e1648da  ../bb--set.log
99970f198535e5fe62aeec1a13ebc639  ../dash--set.log
28583c502cf605e105f794a37e1648da  ../ksh--set.log
99970f198535e5fe62aeec1a13ebc639  ../mksh--set.log
4008c14ae7f0b2195c96d330d604ae50  ../zshdn--set.log
28583c502cf605e105f794a37e1648da  ../zsh--set.log

Strangely, the two zsh tests i did aren't the same.

  parent reply	other threads:[~2015-01-19 21:44 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 [this message]
     [not found]     ` <54BD7ABB.5070501__36205.2317861982$1421704010$gmane$org@gmx.com>
2015-01-19 23:05       ` Stephane Chazelas
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=54BD7ABB.5070501@gmx.com \
    --to=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).