Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Equivalent of set -- *(DN) in sh



19.01.2015, 18:55, "ZyX" <kp-pav@xxxxxxxxx>:
> 19.01.2015, 18:51, "ZyX" <kp-pav@xxxxxxxxx>:
>>  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.
>
> No, this may make duplicates. Then `'..?*'`.

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 `[^.]`.

>>>     if match $pat; then
>>>       set -- "$@" $pat
>>>     fi
>>>   done
>>>   unset pat
>>>
>>>   test "$#" -gt 0 && printf '%s\n' "$@"



Messages sorted by: Reverse Date, Date, Thread, Author