From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2690 invoked by alias); 18 Oct 2013 15:43:58 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31841 Received: (qmail 13119 invoked from network); 18 Oct 2013 15:43:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f4-b7f0a6d000007b1b-29-526154d1d395 Date: Fri, 18 Oct 2013 16:33:36 +0100 From: Peter Stephenson To: Filip Krska , zsh-workers@zsh.org Subject: Re: zsh syntax check fails on correct if [[ usage (rhbz 966911) Message-id: <20131018163336.5b9beef3@pwslap01u.europe.root.pri> In-reply-to: <52613F82.1000009@redhat.com> References: <52613F82.1000009@redhat.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOLMWRmVeSWpSXmKPExsVy+t/xq7oXQxKDDFpfCVgcPXuSxeJg80Mm ByaP9/uusnmsOviBKYApissmJTUnsyy1SN8ugSvjxP9NbAUPuSouXb/I2MC4jKOLkZNDQsBE orVpFiOELSZx4d56ti5GLg4hgaWMEgeXrmOHcPqZJGb9Pc4MUsUioCox8dlzNhCbTcBQYuqm 2WDdIgIWEnvv7GACsYUFPCQ+z3rICmLzCthLTLw+nx3E5hTQkti6azqYLSSgKfFo+3Ywm19A X+Lq309MEFfYS8y8coYRoldQ4sfkeywgNjNQ7+ZtTawQtrzE5jVvmScwCsxCUjYLSdksJGUL GJlXMYqmliYXFCel5xrqFSfmFpfmpesl5+duYoQE5pcdjIuPWR1iFOBgVOLhfWCXGCTEmlhW XJl7iFGCg1lJhLfMGSjEm5JYWZValB9fVJqTWnyIkYmDU6qBkYfh1/W2c8syKk/1HbjKsmWn 9pVq5aZVjXv2lecKbGCWevZ965bJfFGb5H6dbdpTsfvc7Llls2sWCLZetjgxWVBv35WOQOYv 2boOD1jZ3zest139bpPFIYUdjdenmNj9vbO6dqt9dvGaDUEz7m3eM33eWue0vJPbYvnj2ZLk hDL1tlmk+PVsq1RiKc5INNRiLipOBACISq+lKgIAAA== On Fri, 18 Oct 2013 16:02:42 +0200 Filip Krska 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