For the sake of this question, assume that the glob /a/b/c/*
produces no matches.
This means that the following test should fail (in other words, it should produce a non-zero $?
):
[[ -n /a/b/c/*(#qN) ]]
This is in fact the case if I run the test directly on the (zsh) command line. However, if I stick the exact same test in a script, it succeeds, which is not the intended behavior.
If I run the same script with the -x
flag, the resulting trace shows the test as
[[ -n '/a/b/c/*(#qN)' ]]
I do not understand why the single quotes appear around test's argument; in the script's source code there are no quotes at all.
If zsh automatically inserts these single quotes, this would explain why the text succeeds.
Questions:
- why is there a difference between the command-line and script versions of this expression?
- what do I need to do so that the test (correctly) fails when it is in the script?
extended_glob
shell option set in both the interactive shell and the script?extendedglob
is set in my interactive environment, but not in the script.