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


Groups > comp.unix.shell > #26843

Re: shell function or shell script?

From Helmut Waitzmann <nn.throttle@erine.email>
Newsgroups comp.unix.shell
Subject Re: shell function or shell script?
Date 2026-05-13 23:28 +0200
Organization A noiseless patient Spider
Message-ID <83pl2zrodb.fsf@helmutwaitzmann.news.arcor.de> (permalink)
References <slrn11062qn.n9t.hymie@nasalinux.net> <83fr3wtt0r.fsf@helmutwaitzmann.news.arcor.de> <10u0gho$1l93k$11@dont-email.me>

Show all headers | View raw


 Janis Papanagnou <janis_papanagnou+ng@hotmail.com>:
> On 2026-05-12 19:52, Helmut Waitzmann wrote:
>> It might be very hard or even impossible to make a shell 
>> function free of its context.  For example, a shell function 
>> might iterate over its given positional parameters: 
>>
>
> That's one reason why I'm using Kornshell functions (as opposed 
> to  POSIX functions), that allow you to iterate separately from 
> the top-level script getopts over its own arguments in its own 
> context, and not interfering. 
>

 The problem I presented is not related to getopts but to the fact 
 that a readonly variable neither can be assigned a new value nor 
 can be unset – even if the assignment resp.  unset statement 
 occurs in a subshell environment. 


 Are you going to say that that won't fail using Kornshell?  So, 
 what would be the working Kornshell equivalent to the not‐working 
 command 


   (
     sum()
     (
       sum=0 &&
       for arg
       do
         sum="$(( sum + arg ))"
       done &&
       printf '%s\n' "$sum"
     ) &&
     readonly arg sum && sum 1 2 3
   )

 when given to a POSIX‐Shell? 

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