Date: Sat, 13 Aug 2005 21:06:35 -0500 From: Bob Willcox <bob@immure.com> To: Colin Percival <cperciva@freebsd.org> Cc: cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org Subject: Re: cvs commit: src/usr.sbin/portsnap/portsnap portsnap.sh Message-ID: <20050814020635.GA19321@luke.immure.com> In-Reply-To: <42FE6A67.6000208@freebsd.org> References: <200508132128.j7DLShWb080387@repoman.freebsd.org> <42FE6A67.6000208@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Aug 13, 2005 at 02:47:19PM -0700, Colin Percival wrote: > Colin Percival wrote: > > This bug was caused by the astonishing interaction of "return" and > > pipelines; in the following code, the "return" does not exit the > > function, but instead exits the subshell which was spawned for the last > > element of the pipeline; consequently, the output produced is "foo". > > > > foo() { > > echo bar | while read baz; do > > if [ ${baz} = "bar" ]; then > > return 1 > > fi > > done > > > > echo foo > > } > > For what it's worth, I don't know if the behaviour of our sh(1) is correct > here. IEEE 1003.1, 2004 Ed. says > > "The return utility shall cause the shell to stop executing the current function > or dot script. If the shell is not currently executing a function or dot script, > the results are unspecified." > > and I don't see any mention of not returning from a function just because we > happen to be inside a subshell. I tried this on a some different shells. Turns out that bash & pdksh behave similar to the FreeBSD shell, but with ksh93 the return exits the function. So maybe ksh93 is the only one working correctly--or it's the only one that's broke. Bob > > Colin Percival > _______________________________________________ > cvs-all@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/cvs-all > To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org" -- Bob Willcox The early bird who catches the worm works for someone bob@immure.com who comes in late and owns the worm farm. Austin, TX -- Travis McGee
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050814020635.GA19321>