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

Re: zsh syntax check fails on correct if [[ usage (rhbz 966911)



On Fri, 18 Oct 2013 16:02:42 +0200
Filip Krska <fkrska@xxxxxxxxxx> 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



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