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

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



2018-03-14 10:54:42 +0000, Peter Stephenson:
[...]
> 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);


Thanks. I think that code explains why we don't report an error
upon read errors ($(</), $(</dev/mem)) as we use the same
function that reads the output of normal command substitutions
where read errors are not expected (pipe).

I suppose it's the same in other shells.

Would it be worth doing some:

  	ret = readoutput(stream, qt);
	if (errno) {
	  zwarn("%e: %s", errno, s);
	  lastval = cmdoutval = 1;
	}
	return ret;

there (or something cleaner to avoid relying on errno)?

-- 
Stephane



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