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


Groups > comp.unix.shell > #26833

Re: shell function or shell script?

From Christian Weisgerber <naddy@mips.inka.de>
Newsgroups comp.unix.shell
Subject Re: shell function or shell script?
Date 2026-05-12 18:46 +0000
Message-ID <slrn1106tca.a5a.naddy@lorvorc.mips.inka.de> (permalink)
References <slrn11062qn.n9t.hymie@nasalinux.net> <10tvkap$1l93k$10@dont-email.me>

Show all headers | View raw


On 2026-05-12, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

> POSIX functions, 'f()', may make use of side effects, while
> Kornshell functions, 'function f', may have local variables,
> own signal handling, own 'getopts' parameter processing.

Side note: The syntax for defining a POSIX function is actually

f() command

The commonly used braces { ... } are _not_ part of the syntax.  You
can define a minimal shell function that consists of a single
command.  For multiple commands, you need to use a form of grouping,
which is where the braces come in.  However, you can also use
( ... ) to inherently run the function body in a subshell.

f() ( ... )

I have actually used this.

-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de

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


Thread

shell function or shell script? hymie! <hymie@nasalinux.net> - 2026-05-12 11:13 +0000
  Re: shell function or shell script? gmc@metro.cx (Koen Martens) - 2026-05-12 16:13 +0000
  Re: shell function or shell script? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-12 18:26 +0200
    Re: shell function or shell script? Christian Weisgerber <naddy@mips.inka.de> - 2026-05-12 18:46 +0000
      Is a shell function body consisting of other than a grouping command syntactically valid? (was: shell function or shell script?) Helmut Waitzmann <nn.throttle@erine.email> - 2026-05-12 23:45 +0200
        Re: Is a shell function body consisting of other than a grouping command syntactically valid? (was: shell function or shell script?) Christian Weisgerber <naddy@mips.inka.de> - 2026-05-13 13:33 +0000
      Re: shell function or shell script? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-13 02:18 +0200
        Re: shell function or shell script? Christian Weisgerber <naddy@mips.inka.de> - 2026-05-13 13:44 +0000
          Re: shell function or shell script? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-14 01:22 +0200
      Re: shell function or shell script? Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2026-05-13 13:34 +0100
        Random ramblings about various shell stuff (Was: [long ago and far away] shell function or shell script?) gazelle@shell.xmission.com (Kenny McCormack) - 2026-05-13 12:52 +0000
  Re: shell function or shell script? Helmut Waitzmann <nn.throttle@erine.email> - 2026-05-12 19:52 +0200
    Re: shell function or shell script? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-13 02:27 +0200
      Re: shell function or shell script? Helmut Waitzmann <nn.throttle@erine.email> - 2026-05-13 23:28 +0200
        Re: shell function or shell script? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-14 01:20 +0200
          Re: shell function or shell script? Helmut Waitzmann <nn.throttle@erine.email> - 2026-05-14 19:03 +0200
            Re: shell function or shell script? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-15 04:10 +0200
  Re: shell function or shell script? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-12 21:16 +0000
    Re: shell function or shell script? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-13 02:33 +0200

csiph-web