If there is no match for *aaa*
an error is reported by default. This is what causes your script to exit.
To avoid this the NULL_GLOB
option has to be set. Then instead of reporting an error the pattern is simply removed from the argument list, if nothing matches.
There are several ways to set NULL_GLOB:
- for the whole script by passing the
-G
command line option tozsh
. This can also be done on the hash-bang line:
$ zsh -G SCRIPT
#!/usr/bin/zsh -G for f (*aaa*) for f (*bbb*)
- for all following lines by setting it with setopt:
setopt NULL_GLOB for f (*aaa*) for f (*bbb*)
- for a single pattern by using the glob qualifier
N
:
for f (*aaa*(N)) for f (*bbb*)