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

Re: $(<nofile) doesn't set $? to non-zero



On Wed, 14 Mar 2018 10:32:54 +0000
Stephane Chazelas <stephane.chazelas@xxxxxxxxx> wrote:
> $ zsh -c 'ar=$(<file); echo "$?"'
> zsh:1: no such file or directory: file
> 0
> 
> That's different from other shells (ksh93, bash, mksh) that
> return 1, and is also inconsistent with the cases where $(<) is
> not recognised as that operator and runs the NULLCMD instead:

We set lastval = cmdoutval if it's an ordinary command substitution, so it's
easy to make this consistent with that behaviour.  Doing so seems
unproblematic.

pws

diff --git a/Src/exec.c b/Src/exec.c
index e5c6455..299b816 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4514,6 +4514,7 @@ getoutput(char *cmd, int qt)
 	untokenize(s);
 	if ((stream = open(unmeta(s), O_RDONLY | O_NOCTTY)) == -1) {
 	    zwarn("%e: %s", errno, s);
+	    lastval = cmdoutval = 1;
 	    return newlinklist();
 	}
 	return readoutput(stream, qt);



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