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

[PATCH] respect nullglob given multios



This patch makes multios behave less surprisingly with nullglob.

Currently, multios throws a file not found error when a nullglob is given. This patch inserts /dev/null into the redirection list when the glob returns empty with no errors.

Is this a behavior that would interest anyone else? I find myself using the `cat /dev/null *(N.)` idiom quite a bit and I thought the behavior made sense for the null case in multios.

Joe

diff --git a/Src/glob.c b/Src/glob.c
index 92fd64e7c..a708dfb9a 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -2116,8 +2116,11 @@ xpandredir(struct redir *fn, LinkList redirtab)
     /* ...which undergoes all the usual shell expansions */
     prefork(&fake, isset(MULTIOS) ? 0 : PREFORK_SINGLE, NULL);
     /* Globbing is only done for multios. */
-    if (!errflag && isset(MULTIOS))
+    if (!errflag && isset(MULTIOS)) {
        globlist(&fake, 0);
+       if (empty(&fake) && !errflag && !badcshglob)
+           addlinknode(&fake, dupstring("/dev/null"));
+    }
     if (errflag)
        return 0;
     if (nonempty(&fake) && !nextnode(firstnode(&fake))) {


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