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

Re: whence question



On Sat, Jan 14, 2017 at 06:48:07AM +0000, Daniel Shahaf wrote:
> Ray Andrews wrote on Fri, Jan 13, 2017 at 22:09:54 -0800:
...
> > I know that if a glob has  no match it's passed verbatim so whence
> > sees what it's supposed to see,
> 
> That's only true when 'setopt nonomatch' is in effect, which is not the
> default.  By default, globs that have no match are considered errors.
> The NULL_GLOB option selects a third mode.  See:
> 
>     % cd $(mktemp -d)
>     % echo foo*
>     zsh: no matches found: foo*
>     % (setopt nullglob; echo foo*) | nl -ba
>     
>     % (setopt nonomatch; echo foo*)
>     foo*
>     % 
> 
> > [...] I can see that without 'noglob' the shell's zeal for expanding
> > globs is in more or less direct conflict with the intention of the 'm'
> > switch which supposes that whence will handle globing itself.  I can
> > also see that that might not be fixable even in theory for reasons of
> > consistency,
> 
> Right: while there are several ways to make a shell builtin command see
> globs in arguments, the default behaviour of existing (released)
> commands can't be changed for compatibility reasons.
> 
> Also, the existing design has merits: *every* external and builtin
> command parses "words with globbing metacharacters" the same way.
> «echo *foo» and «whence *foo» and «bar *foo» are all subject to the
> same rules.  The rules are consistent for everybody.  That's a feature.

I also prefer the default (i.e. use literal if no match), because it is
IMHO safer than just dropping it (and opt. emit an err msg). However,
especially in 'for' like statements, dropping it silently makes sense
(is expected). To accomplish this in an easy way, ksh93 allows one to
prefix the pattern with '~(N)' , e.g.:
for F in ~(N)*.c ; do ls $F ; done
or
for F in ~(N)*.c ; do ls ${F%.c}/*.o ; done

Would be nice, if zsh could do the same (and enhance compatibility) ...

Have fun,
jel.
-- 
Otto-von-Guericke University     http://www.cs.uni-magdeburg.de/
Department of Computer Science   Geb. 29 R 027, Universitaetsplatz 2
39106 Magdeburg, Germany         Tel: +49 391 67 52768



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