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

Re: whence question



Ray Andrews wrote on Fri, Jan 13, 2017 at 22:09:54 -0800:
> On 13/01/17 09:11 PM, Bart Schaefer wrote:
> >To expound a little on Daniel's answer, [...]

Thanks, Bart.

> 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.

The most ${adjective} exception to the rule is the '[[' reserved word;
but note that its older variant, '[', abides by the rule.

Cheers,

Daniel
[sorry for that botched interpolation in the last paragraph; I had
nonomatch enabled in my compose window's parameter interpolation code
while I was writing this email. ;-)]



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