Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: nomatch/cshnullglob problems
- X-seq: zsh-users 10116
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: nomatch/cshnullglob problems
- Date: Fri, 31 Mar 2006 01:52:18 -0800
On Mar 31, 10:02am, Michael Wardle wrote:
}
} It seems that sometimes, CSH_NULL_GLOB causes an error even if some of
} the file names in the list match.
[...]
} According to the manual:
} CSH_NULL_GLOB <C>
} If a pattern for filename generation has no matches, delete the
} pattern from the argument list; do not report an error unless all
} the patterns in a command have no matches. Overrides NOMATCH.
Right: Do not report an error unless all the PATTERNS have no matches.
There is exactly one pattern in your sample command (/opt/*/bin), and
it has no matches. Any other argument strings with no wildcards in them
are not patterns; the shell doesn't test, or care, whether they "match"
anything.
} It also seems that such an error is fatal when using "source" or "."
} (dot).
It's not "fatal" or the whole shell would exit ...
} If I add a "set -o | grep err", I can see that neither ERR_EXIT nor
} ERR_RETURN are set, so I would have expected the sourcing of the script
} to complete and print "finish" like when it's run as a script.
This is another case where zsh behaves like csh. If you try this same
thing in tcsh, you'll find a "source"d file stops at the same point.
This behavior is considered more useful because, e.g., it prevents
unexepcted commands from being executed from startup files in the event
of an error in setting up a conditional.
Apparently this never made it into the zsh manual because (at the time,
when 4.x BSD and csh were widely in use and zsh users were more often
switch form csh than from a Bourne-like shell) it's such a well-known
csh behavior.
} The same directory list containing the /opt/*/bin wildcard seems to
} work fine in tcsh, which the CSH_NULL_GLOB option should be emulating.
Really? Here's tcsh on my system:
[schaefer@torch ~]$ foreach x (/opt/*/bin /usr/X11R6/bin /usr/kerberos/bin
/usr/posix/bin /usr/gnu/bin /usr/local/bin "$HOME"/bin)
foreach: No match.
[schaefer@torch ~]$ foreach x ( /opt/*/bin /usr/X*6/bin /usr/kerberos/bin
/usr/posix/bin /usr/gnu/bin /usr/local/bin "$HOME"/bin )
foreach? end
[schaefer@torch ~]$
Note it works if there are two patterns, one of which doesn't match.
} If the option only comes into effect if there are multiple wildcards
} (globbing characters) in the same list, then what is its use, and how
} can I get the result I want?
In your specific example, you probably want just plain NULL_GLOB, which
you can turn on for a single pattern thusly:
for dir
in /opt/*/bin(N) /usr/X11R6/bin /usr/kerberos/bin \
/usr/posix/bin /usr/gnu/bin /usr/local/bin "$HOME"/bin
Messages sorted by:
Reverse Date,
Date,
Thread,
Author