Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [bug] redirections and nullglob+multios
- X-seq: zsh-workers 53959
- From: Jun T <takimoto-j@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: [bug] redirections and nullglob+multios
- Date: Mon, 22 Sep 2025 13:44:07 +0900
- Archived-at: <https://zsh.org/workers/53959>
- In-reply-to: <64okckg3upcg27vj4avlcwhevmi6t7qv2vfsxlkvtqe3f6lxzd@elcagu6ixgsh>
- List-id: <zsh-workers.zsh.org>
- References: <64okckg3upcg27vj4avlcwhevmi6t7qv2vfsxlkvtqe3f6lxzd@elcagu6ixgsh>
> 2025/09/19 13:16, Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> With multios on (default) and nullglob on or (N), (#qN) glob
> qualifier, I find (in an empty directory):
>
> $ zsh -c 'echo > xxx(N)'
> $ ls
> 'xxx'$'\210''N'$'\212'
(snip)
The patch below may work, but I will not push it.
It would be better to deal with the error in expandredir().
We can check the result of glob by empty(&fake), and check the option
by isset(NULLGLOB), but we can't know whether the qualifier (N) or (#qN)
is used or not.
So I used a variable in_expandredir to notify zglob() that it is called
from expandredir(). But, yes, this is ugly.
Is there any better way?
diff --git a/Src/glob.c b/Src/glob.c
index 3e34f708e..880521ad9 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -1202,6 +1202,9 @@ checkglobqual(char *str, int sl, int nobareglob, char **sp)
return ret;
}
+/* notify zglob() that it is called from expandredir() */
+static int in_expandredir = 0;
+
/* Main entry point to the globbing code for filename globbing. *
* np points to a node in the list which will be expanded *
* into a series of nodes. */
@@ -1880,6 +1883,14 @@ zglob(LinkList list, LinkNode np, int nountok)
matchct = 1;
}
}
+ else if (in_expandredir) {
+ /* if completing for redirection, we can't remove the pattern
+ * even if NULGLOB is in effect */
+ zerr("redirection failed (no match): %s", ostr);
+ zfree(matchbuf, 0);
+ restore_globstate(saved);
+ return;
+ }
if (!(gf_sortlist[0].tp & GS_NONE)) {
/*
@@ -2146,8 +2157,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)) {
+ in_expandredir = 1;
globlist(&fake, 0);
+ in_expandredir = 0;
+ }
if (errflag)
return 0;
if (nonempty(&fake) && !nextnode(firstnode(&fake))) {
Messages sorted by:
Reverse Date,
Date,
Thread,
Author