Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Aug 2010 00:33:14 -0700
From:      Brian Somers <brian@FreeBSD.org>
To:        Jilles Tjoelker <jilles@FreeBSD.org>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org
Subject:   Re: svn commit: r211609 - head/tools/regression/bin/sh/builtins
Message-ID:  <20100823003314.57d41b94@dev.lan.Awfulhak.org>
In-Reply-To: <201008221104.o7MB4Ung001538@svn.freebsd.org>
References:  <201008221104.o7MB4Ung001538@svn.freebsd.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On Sun, 22 Aug 2010 11:04:30 +0000 (UTC) Jilles Tjoelker <jilles@FreeBSD.org> wrote:
> Author: jilles
> Date: Sun Aug 22 11:04:30 2010
> New Revision: 211609
> URL: http://svn.freebsd.org/changeset/base/211609
> 
> Log:
>   sh: Add a test for breaking from a loop outside the current function.
>   
>   It is unwise to rely on this but I'd like to know if this would break.
> 
> Added:
>   head/tools/regression/bin/sh/builtins/break3.0   (contents, props changed)
> 
> Added: head/tools/regression/bin/sh/builtins/break3.0
> ==============================================================================
> --- /dev/null	00:00:00 1970	(empty, because file is newly added)
> +++ head/tools/regression/bin/sh/builtins/break3.0	Sun Aug 22 11:04:30 2010	(r211609)
> @@ -0,0 +1,15 @@
> +# $FreeBSD$
> +
> +# We accept this and people might rely on it.
> +# However, various other shells do not accept it.
> +
> +f() {
> +	break
> +	echo bad1
> +}
> +
> +while :; do
> +	f
> +	echo bad2
> +	exit 2
> +done

This feature should be counted as a bug IMHO.  How can f() possibly know whether
there's a surrounding context to break from?

Having said that, this behaviour is the same in bash except that bash will complain if
it's asked to break when the context is wrong, perhaps we should complain too?

$ bash -c 'f() { break; echo no break; }; for f in good bad; do echo $f; f; done'
good
$ sh -c 'f() { break; echo no break; }; for f in good bad; do echo $f; f; done'
good
$ bash -c 'f() { break; echo no break; }; f'
bash: line 0: break: only meaningful in a `for', `while', or `until' loop
no break
$ bash -c 'f() { break 2>/dev/null; echo no break; }; f'
no break
$ sh -c 'f() { break; echo no break; }; f'
no break

-- 
Brian Somers                                          <brian@Awfulhak.org>
Don't _EVER_ lose your sense of humour !               <brian@FreeBSD.org>

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iQCVAwUBTHIkQQ7tvOdmanQhAQJuvwP/YrtETlwy1MFtF6KPtovatQukjMX5wpWw
FMX+Efgkvv6QEKYD777fngWl3igOKx2KE8Zm11sQo45r2cgfrOK5Nl1xMzQD4Neo
WaCX35wwPjD+QupFOWN59XWxTroV/s1ct7DgKbscj8zvEMMwkgoK21eIoWH8kRHO
b6GUHEosUQ4=
=kB8L
-----END PGP SIGNATURE-----
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100823003314.57d41b94>