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

NOMATCH errors


I was dusting off an old script which, admittedly inelegantly, did
  PYTHON==python 2>/dev/null
with NOMATCH set, which in the zsh 5 era seems to be a fatal error, i.e.
a script

echo hello
echo =hello =hello
echo "is there anybody in there?"

doesn't get past:
hello:2: hello not found

Interestingly the docs perhaps arguably seem to imply differently:
   Fatal errors found in non-interactive shells include:
   o    File generation failures where not caused by NO_MATCH or similar

So I was wondering the cleanest way to do this.  `which python` is the
way, I guess, but the documentation isn't very reassuring about output
in case it happens to be an alias or a function or (heaven forfend)
python becomes
a shell builtin. 

I played for a few minutes with a trivial patch at the end of this
email, which
aimed to make ==missing expand to an empty string.   That to me seems a
behaviour,  enables e.g. ${${:-==python}:-perl},  although it feels very
case syntax, maybe something as a variant or modifier on the :c
expansion would be
neater.  But then if the idea is valid, maybe it sense to be able to
soft test tilde dir
expansion too;  I'm not aware a nice way to look up single entries in
the hash tables, so maybe a general syntax for that could be better.

Any thoughts appreciated,  especially if I'm missing a neat way to do



--- a/Src/subst.c
+++ b/Src/subst.c
@@ -623,13 +623,18 @@ char *
 equalsubstr(char *str, int assign, int nomatch)
     char *pp, *cnam, *cmdstr, *ret;
+    int nullmatch = str[0] == Equals;
     for (pp = str; !isend2(*pp); pp++)
     cmdstr = dupstrpfx(str, pp-str);
+    if (nullmatch)
+       cmdstr++;
     if (!(cnam = findcmd(cmdstr, 1, 0))) {
+       if (nullmatch)
+           return dupstring("");
        if (nomatch)
            zerr("%s not found", cmdstr);
        return NULL;

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