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

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



# now@xxxxxxx / 2015-01-18 20:43:55 +0100:
> On Sun, Jan 18, 2015 at 8:07 PM, Roman Neuhauser <neuhauser@xxxxxxxxxx> wrote:
> > # now@xxxxxxx / 2015-01-18 19:28:42 +0100:
> >> 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.
> >
> > set -- $(find .* * -maxdepth 0 -type d)
> >
> > does not handle names with spaces.
> 
> Which is unsatisfactory, as $() isn´t in all versions of sh,

then use `find ...`, problem solved.

btw if your requirements are this stringent you would have done well
if you laid them out upfront.

> -maxdepth is GNU specific

it's not, at least all BSDs have it as well.  again, what operating
systems do you need to support?

> and .* and * will be expanded by the shell, not by find

you can `find . -maxdepth 1 -mindepth 1`, but the paths will be prefixed
with "./".  you could of ocurse append `| sed 's:..::'`.

OTOH, what's the problem with the shell expanding the globs?
if .* or * does not exist, sh leaves that there as-is, find cannot
chdir into it, and definitely won't print it.

> Oh, and who said anything about only including directories?  ;-)

yeah, that was a brainfart, sorry.

-- 
roman



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