zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Filip Krska <fkrska@redhat.com>, zsh-workers@zsh.org
Subject: Re: zsh syntax check fails on correct if [[ usage (rhbz 966911)
Date: Fri, 18 Oct 2013 16:33:36 +0100	[thread overview]
Message-ID: <20131018163336.5b9beef3@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <52613F82.1000009@redhat.com>

On Fri, 18 Oct 2013 16:02:42 +0200
Filip Krska <fkrska@redhat.com> wrote:
> $ cat /tmp/test.zsh
> #!/bin/zsh
> 
> if [[ $# -eq 1 ]]
> then
>    THE_USER=$1
> else
>    THE_USER=$(whoami)
> fi
> 
> 2. execute test
> $ zsh -n /tmp/test.zsh
> 
> 3. observe exit value
> $ echo $?
> 1

Yes, that's wrong.  It looks like when $(...) doesn't run anything
because of NO_EXEC it's keeping the status value from the parent shell,
which isn't useful.  (That's where the test above comes into the problem
--- it's setting the internal status to 1.)  I think we need to
initialise the status to 0 after the fork.  I haven't checked, but
presumably when NO_EXEC isn't set it gets far enough that's initialised
at some later point, but I don't think there's ever a case where the
forked shell should inherit the status -- in fact, maybe this should go
in entersubsh(), or is that too dangerous?

This may need to go after other forks, and then I should add a test.

diff --git a/Src/exec.c b/Src/exec.c
index 8efbbd4..5e65e1b 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3743,6 +3743,7 @@ getoutput(char *cmd, int qt)
     redup(pipes[1], 1);
     entersubsh(ESUB_PGRP|ESUB_NOMONITOR);
     cmdpush(CS_CMDSUBST);
+    lastval = 0; /* if nothing is executed, status is 0 */
     execode(prog, 0, 1, "cmdsubst");
     cmdpop();
     close(1);

pws


  reply	other threads:[~2013-10-18 15:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-18 14:02 Filip Krska
2013-10-18 15:33 ` Peter Stephenson [this message]
2013-10-18 19:12   ` Peter Stephenson
2013-10-18 15:48 ` Bart Schaefer
2013-10-18 15:56   ` Peter Stephenson
2013-10-18 19:20     ` Bart Schaefer
2013-10-18 22:43       ` Peter Stephenson
2013-10-19 21:19         ` Bart Schaefer
2013-10-19 21:46           ` Bart Schaefer
2013-10-19 21:56           ` Peter Stephenson
2013-11-20 14:08             ` Filip Krska
2013-10-18 19:29   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131018163336.5b9beef3@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=fkrska@redhat.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).