Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.unix.shell > #4215

Re: shell function... new subshell

Newsgroups comp.unix.shell
From Geoff Clare <geoff@clare.See-My-Signature.invalid>
Subject Re: shell function... new subshell
References <c12a09ef-1354-4172-8187-cd5cb1de6744@p13g2000yqd.googlegroups.com> <jibqh1$u7j$3@news.xmission.com> <de6cf7d2-261d-48d5-9872-82e52a2e53c7@l7g2000vbw.googlegroups.com> <jic7nc$tbt$1@dont-email.me> <slrnjkmh2c.t1k.vaeth@lounge.imp.fu-berlin.de>
Date 2012-02-27 13:51 +0000
Message-ID <ebes19-jbf.ln1@leafnode-msgid.gclare.org.uk> (permalink)
Organization Zen Internet

Show all headers | View raw


Martin Vaeth wrote:

> Mirko K. <mirkok.lists@googlemail.com> 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 <netnews@gclare.org.uk>

Back to comp.unix.shell | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

shell function... new subshell G Patel <gaya.patel@gmail.com> - 2012-02-25 15:02 -0800
  Re: shell function... new subshell gazelle@shell.xmission.com (Kenny McCormack) - 2012-02-25 23:23 +0000
    Re: shell function... new subshell G Patel <gaya.patel@gmail.com> - 2012-02-25 18:23 -0800
      Re: shell function... new subshell "Mirko K." <mirkok.lists@googlemail.com> - 2012-02-26 04:08 +0100
        Re: shell function... new subshell pk <pk@pk.invalid> - 2012-02-26 13:40 +0100
        Re: shell function... new subshell Martin Vaeth <vaeth@mathematik.uni-wuerzburg.de> - 2012-02-27 08:52 +0000
          Re: shell function... new subshell "Mirko K." <mirkok.lists@googlemail.com> - 2012-02-27 13:11 +0100
            Re: shell function... new subshell Martin Vaeth <vaeth@mathematik.uni-wuerzburg.de> - 2012-02-27 18:22 +0000
          Re: shell function... new subshell Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2012-02-27 13:51 +0000
            Re: shell function... new subshell Martin Vaeth <vaeth@mathematik.uni-wuerzburg.de> - 2012-02-27 17:49 +0000
              Re: shell function... new subshell Sven Mascheck <mascheck@email.invalid> - 2012-02-27 18:11 +0000
              Re: shell function... new subshell Stephane Chazelas <stephane_chazelas@yahoo.fr> - 2012-02-27 19:53 +0000
                Re: shell function... new subshell Martin Vaeth <vaeth@mathematik.uni-wuerzburg.de> - 2012-02-28 13:17 +0000

csiph-web