zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Philippe Troin <phil@fifi.org>
Cc: zsh-workers@sunsite.dk
Subject: Re: For loop bug
Date: Mon, 16 Sep 2002 06:25:50 +0000	[thread overview]
Message-ID: <1020916062550.ZM29286@candle.brasslantern.com> (raw)
In-Reply-To: <87elbufs3q.fsf@ceramic.fifi.org>

[Excerpts reordered for clarity.]

On Sep 15,  9:58pm, Philippe Troin wrote:
} Subject: Re: For loop bug
}
} "Bart Schaefer" <schaefer@brasslantern.com> writes:
} 
} > On Sep 13,  5:58pm, Philippe Troin wrote:
} > } 
} > }   % for i in 1 2 3; do { {echo $i; [[ $i == 2 ]] && exit 1; } || break };
} > }   > done && echo X
} > }   1
} > }   X
} > }   % 
} > 
} > That is not a bug.
}
} But shouldn't it print:
} 
}   1
}   2
}   X

No, it shouldn't.  "for i in 1 2 3 ..."

OK, so the first time around the loop i=1, and zsh echoes 1.

Now we're testing [[ $i == 2 ]], which is [[ 1 == 2 ]] which is false;
hence we have { false && exit 1; } which doesn't call exit but also
doesn't evaluate as true, because the first branch of the && is false.

So the outer expression becomes { { false } || break }; and the loop ends
immediately.

} The echo $i with i set to 2 occurs before the exit and break
} statements.

$i never has a chance to get set to 2.

} > Further, { } is not a subshell, so { [[ 2 == 2 ]] && exit 1; } would most
} > likely produce something like
} > 
} > login:
} > 
} > which might surprise you even more.
} 
} I'm not sure I get this part.

If you call { exit 1 } from an interactive zsh, the shell will exit and
you'll end up back at your login prompt (or your xterm will disappear or
your remote connection will drop or whatever).  Expressions in { } are
evaluated in the current shell.  If it were ( exit 1 ) with parens, that's
evaluated in a subshell and the interactive shell would keep running.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


  reply	other threads:[~2002-09-16  6:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-13 18:25 Philippe Troin
2002-09-13 23:31 ` Peter Stephenson
2002-09-14  0:34   ` Bart Schaefer
2002-09-14  0:58   ` Philippe Troin
2002-09-14  4:56     ` Bart Schaefer
2002-09-16  4:58       ` Philippe Troin
2002-09-16  6:25         ` Bart Schaefer [this message]
2002-09-16 18:26           ` Philippe Troin
2002-09-16 20:46             ` Hans Dieter Pearcey
2002-09-17  0:08               ` Philippe Troin
2002-09-14 14:39   ` Peter Stephenson
2002-09-17 10:47     ` Peter Stephenson
2002-09-29 13:20     ` Sven Wischnowsky

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=1020916062550.ZM29286@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=phil@fifi.org \
    --cc=zsh-workers@sunsite.dk \
    /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).