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

nomatch/cshnullglob problems



Hi

There's a couple of things about the NO_MATCH and CSH_NULL_GLOB options
that have surprised me.

It seems that sometimes, CSH_NULL_GLOB causes an error even if some of
the file names in the list match.  It also seems that such an error is
fatal when using "source" or "." (dot).

If I create a script called "globtest" with the following contents,
-----
#!/bin/zsh

setopt cshnullglob
unsetopt nomatch
echo start
for dir
in /opt/*/bin /usr/X11R6/bin /usr/kerberos/bin /usr/posix/bin /usr/gnu/bin /usr/local/bin "$HOME"/bin
do
    test -d "$dir" && echo "$dir"
done
echo finish
-----

set it executable, then run "./globtest", I get the following output:
-----
start
globtest:6: no match
finish
-----

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.

I this case, I would expect the output to be the same as when the third
line is changed to "unsetopt cshnullglob":
-----
start
/usr/X11R6/bin
/usr/local/bin
/home/michael/bin
finish
-----

since the non-matching "/opt/*/bin" should be removed from the list,
leaving /usr/X11R6/bin /usr/kerberos/bin, etc., and no error should be
reported.

The same directory list containing the /opt/*/bin wildcard seems to work
fine in tcsh, which the CSH_NULL_GLOB option should be emulating.

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?

Further, if I run ". globtest", I get the following output:
-----
start
globtest:6: no match
-----

which suggests that the "." command terminates as soon as an error is
encountered.

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.  (The
same script does complete and print "finish" when sourcing the script in
bash.)

I'm running zsh 4.2.5 on Ubuntu Linux.

Is this a bug or the expected behavior?

Thanks

Michael



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