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

Re: globbing in conditional expressions



On May 30,  8:55am, Bart Schaefer wrote:
}
} Is there a non-convoluted way to have the special case of a glob with
} BOTH of the (NY) qualifiers return empty string rather than nularg when
} it finds no match?  Empty string is an illegal file name so for most
} purposes it wouldn't otherwise affect usage.

This turns out to be pretty simple.  It'd additionally be nice if the
CSH_NULL_GLOB option caused any such empty strings to be removed when
some other pattern succeeds, but that seems rather far-reaching.  (The
following will require a tweak to Daniel's test in D02glob.)

diff --git a/Src/glob.c b/Src/glob.c
index 07dd7c2..5aa306b 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -1748,6 +1761,11 @@ zglob(LinkList list, LinkNode np, int nountok)
 	    matchptr++;
 	    matchct = 1;
 	}
+    } else if (shortcircuit) {
+      /* treat as an empty string */
+      matchptr->name = dupstring("");
+      matchptr++;
+      matchct = 1;
     }
 
     if (!(gf_sortlist[0].tp & GS_NONE)) {



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