zsh-workers
 help / color / mirror / code / Atom feed
* Re: 'continue' does not work in files sourced with dotcmd
       [not found]     ` <20110707144635.GA21272@gondor.apana.org.au>
@ 2011-07-07 15:18       ` Eric Blake
  2011-07-08  8:09         ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Blake @ 2011-07-07 15:18 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Taylan Ulrich B., dash, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 2328 bytes --]

[adding zsh list]

On 07/07/2011 08:46 AM, Herbert Xu wrote:
> On Thu, Jul 07, 2011 at 07:26:50AM -0600, Eric Blake wrote:
>>
>> zsh rejected the continue statement (no containing loop within the
>> current scoping of the dot script), and as a result also aborted the
>> overall dot script - but in doing so, it properly emitted an error message.
> 
> dash does not warn in this case because it never prints a warning
> on continue anywhere.
> 
> This behaviour (not warning) is consistent with that of ksh.

Interesting!  And bash indeed behaves differently: in POSIX mode it is
silent, while in bash mode it issues a warning but does not affect exit
status - in line with the fact that in POSIX mode, bash obeys the rule
that if an application is diagnosing something to stderr, then the exit
status should be non-zero (and warnings don't affect exit status, hence
warnings should not be issued in POSIX mode).

Zsh is treating it as a syntax error, which is different from all the
other shells:

$ bash -c 'continue; echo $?'
bash: line 0: continue: only meaningful in a `for', `while', or `until' loop
0
$ bash --posix -c 'continue; echo $?'
0
$ dash -c 'continue; echo $?'
0
$ ksh -c 'continue; echo $?'
0
$ zsh -c 'emulate sh; continue; echo $?'
zsh:continue:1: not in while, until, select, or repeat loop
$ echo $?
1

POSIX states "If n is greater than the number of enclosing loops, the
outermost enclosing loop shall be exited."  But this is admittedly
silent on the behavior when there is no outermost enclosing loop, so I'm
not sure whether zsh treating this as a syntax error is appropriate.

Meanwhile, I still have to wonder about dash behavior - if dash is _not_
treating continue as a syntax error, then why is it aborting the dot
script?  Compare:

$ dash -c 'continue
echo $?'
0
$ dash -c 'printf "continue\\necho 0.\$?\\n" > f; for i in 1; do . ./f;
echo 1.$?; done; echo 2.$?'
1.0
2.0

In isolation, execution after an un-nested continue resumed with the
next statement, but in the dot script, execution after the "un-nested"
continue (at least, from the dot script perspective) aborted the dot
script, but without affecting exit status.

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: 'continue' does not work in files sourced with dotcmd
  2011-07-07 15:18       ` 'continue' does not work in files sourced with dotcmd Eric Blake
@ 2011-07-08  8:09         ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2011-07-08  8:09 UTC (permalink / raw)
  To: Eric Blake; +Cc: Taylan Ulrich B., dash, zsh-workers

On Thu, Jul 07, 2011 at 09:18:12AM -0600, Eric Blake wrote:
>
> Meanwhile, I still have to wonder about dash behavior - if dash is _not_
> treating continue as a syntax error, then why is it aborting the dot
> script?  Compare:

This is a consequence of the way continue/break/return is implemented
in dash.

As this construct cannot be used portably anyway, I'm not inclined to
make any changes unless you can do it without increasing the code
size.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-08  8:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <AANLkTimiFku8Uj9haYAxXWyJQOGSV7Uz3i2k75+aMvTU@mail.gmail.com>
     [not found] ` <20110707033749.GB16157@gondor.apana.org.au>
     [not found]   ` <4E15B41A.9020601@redhat.com>
     [not found]     ` <20110707144635.GA21272@gondor.apana.org.au>
2011-07-07 15:18       ` 'continue' does not work in files sourced with dotcmd Eric Blake
2011-07-08  8:09         ` Herbert Xu

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).