Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Equivalent of set -- *(DN) in sh
- X-seq: zsh-users 19747
- From: ZyX <kp-pav@xxxxxxxxx>
- To: Eric Cook <llua@xxxxxxx>, "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: Equivalent of set -- *(DN) in sh
- Date: Mon, 19 Jan 2015 18:51:10 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1421682670; bh=dt4hqiZNL0gV3i5bqm7MaWE6jVfW1oLTUBUZDeZV66A=; h=From:To:In-Reply-To:References:Subject:Date; b=Nh/1XNQWVbJg07I57dvmJ1m0kIQewBeYEzT66ESadzZS3CNMZGZZqD6PPPsW/VJ3x lTn13DXXuI/Hzq+WYUVkzQ7t7tN73Uul0ZhxrnKzVkzYZpe0CaJJYijM71bQD4Ds04 snGEkS5M47WinAIxEvkgP33tCMOco1L4IZUCDWwQ=
- In-reply-to: <54BC1B8E.5080806@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>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADdV=MvMtwYczr82GeYkmVwTFCKgFcbgYS71XdnHZN_JqFqzTg@mail.gmail.com> <54BC1B8E.5080806@gmx.com>
18.01.2015, 23:53, "Eric Cook" <llua@xxxxxxx>:
> On 01/18/2015 01:28 PM, Nikolai Weibull wrote:
>> Hi!
>>
>> Is there any way to get the equivalent of Zsh’s
>>
>> set -- *(DN)
>>
>> in sh? Most important here would be NULL_GLOB, as, by default, sh
>> simply leaves the * if there are no files to match.
>>
>> Thanks!
>
> match() {
> test "$#" -gt 2 && return
> test -e "$1" && return
> return 1
> }
>
> set --
> for pat in '.[^.]*' '*'; do # *(DN) ignores . and ..
`..foo` is a valid name, but it is being excluded. You need to add `'.??*'` to the list of patterns.
> if match $pat; then
> set -- "$@" $pat
> fi
> done
> unset pat
>
> test "$#" -gt 0 && printf '%s\n' "$@"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author