Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!reader02.news.zen.co.uk.POSTED!not-for-mail Newsgroups: comp.unix.shell From: Geoff Clare Subject: Re: shell function... new subshell References: User-Agent: XPN/1.2.6 (Street Spirit ; Linux) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Date: Mon, 27 Feb 2012 13:51:10 +0000 Message-ID: Lines: 38 Organization: Zen Internet NNTP-Posting-Host: 0b59ce87.news.zen.co.uk X-Trace: DXC=EK2\o6CUf2S_]YjZGX^207P[`aFoT>P83MgUBGaZ`97X`@b8VhY X-Complaints-To: abuse@zen.co.uk Xref: x330-a1.tempe.blueboxinc.net comp.unix.shell:4215 Martin Vaeth wrote: > Mirko K. wrote: >> >> Not OK. The shell *does* execute a function in a sub-shell > > No. The real answer is closer to "sort of" than a yes or no (see below). >> if the function body is enclosed in parentheses instead of braces. > > There is nothing like a "function body" which needs to be enclosed > in something. Try: > > Echo() printf '%s\n' "${*}" > Echo a $ Echo() printf '%s\n' "${*}" -bash: syntax error near unexpected token `printf' POSIX says the syntax for a function definition is: fname() compound-command [io-redirect ...] Some shells accept a simple command as an extension, but it's not portable. The compound command that is nearly always used is { ... } but if ( ... ) is used, the shell executes that compound command when the function is called, thus the commands within the ( ... ) are executed in a subshell. Strictly speaking this is the function executing a subshell, not the function itself being "executed in a subshell" (hence the "sort of" answer above). -- Geoff Clare