From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 23884 invoked from network); 4 Jan 2023 18:30:45 -0000 Received: from minnie.tuhs.org (50.116.15.146) by inbox.vuxu.org with ESMTPUTF8; 4 Jan 2023 18:30:45 -0000 Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id 3C82942566; Thu, 5 Jan 2023 04:30:09 +1000 (AEST) Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by minnie.tuhs.org (Postfix) with ESMTPS id 0129742565 for ; Thu, 5 Jan 2023 04:30:04 +1000 (AEST) Received: by mail-qk1-f181.google.com with SMTP id h8so16696343qkk.8 for ; Wed, 04 Jan 2023 10:30:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ck5gWgzz0i9fo5Ta6tE/mjpZpOnkNG0I2X4BQ5cY2mw=; b=LZ6XVKufmwM++rzu1uGltYtIVTyYVdJwCnjKogfC1MQ9fHDfplaE+Blzit75MrSidT PJoCKPYGf1tDt4zyAyBewjlrxV2r87zckeb0J7d+siZJgL+1k/hkgoL2KMd1Xbo+lkjn YkTzKpcPWTYFZr8pVuQhKRQ68s7qC/IFJpfrcYDoo7Kq6u3BUPTNwFn/tDuduyuxnETD BGUSvALdwv+qYo8dVgFs88r1ju6o+nMA5Rq8+BB0Pd7gy9pcNLOb9qxGn9peuSCiIUNu VS/cvbnO05CVq4JEtO2GN3jov4hO7pwM2x6YHVbgukEPdL8oqG3E9n4lsi04jcb5F4Kv uu7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ck5gWgzz0i9fo5Ta6tE/mjpZpOnkNG0I2X4BQ5cY2mw=; b=hjS4EZtuvSRrnGzY+EFNm+jRxePjaLo0Pmw7xtvtP7brWRd79NaoBsTK0CZz931yFL eGfx/XzDwyajqT3j2ZEOWJ1NIyawaYtuz8LrvDDDkek7kap2ZP6rTM0sYGP1Bu440WYH sml47EETxA1EKSlLJ/Fh+ztPifTT3ZwduJ/6UDRir8UnksItiFviwNPfo+nbFAlBVDL8 P/8Bxrs6Voh3UxrhHdsMMjQ75CJ29G4i510I43XtLk5YezZvy5LTyY4xMVEnAn3UOxKR jY/cNG704Eg48pmDdhyWRvmaRHa8Tkz0IzqIeWieiYbL446H6zOcZdemey2oQkYnTvQq VfoQ== X-Gm-Message-State: AFqh2kqbJw7OY0cQS2iclZM9iyPxb1hTp+6iRQ1FqCNV9T+vl9egHorl L31ZU9o1tA+DbZY7P59xnErzdyl5CD9xdkhxNnw= X-Google-Smtp-Source: AMrXdXu39yVREN3Nw4D4mXzSSx6Bq33hrarzCUONDIO4vNx7d8oGAt8B73aZrZ6qe4vrgccyJBwU6SujSGOyCrbhl3Y= X-Received: by 2002:a05:620a:800e:b0:702:6235:2115 with SMTP id ee14-20020a05620a800e00b0070262352115mr2394825qkb.185.1672856944075; Wed, 04 Jan 2023 10:29:04 -0800 (PST) MIME-Version: 1.0 References: <52FB6638-AEFF-4A4F-8C2E-32089D577BA0@planet.nl> <464819f0-d2f6-2a60-6481-a194f4428b4d@case.edu> <20221230200246.GW5825@mcvoy.com> <88f83b4c-b3f9-ed87-b2fa-560fb369742a@makerlisp.com> <20221231035931.GG5825@mcvoy.com> <528f0c53-ccc2-88a1-5a7b-120362c648dd@mhorton.net> <20230102165120.GK25547@mcvoy.com> <20230102174304.GM25547@mcvoy.com> In-Reply-To: From: ron minnich Date: Wed, 4 Jan 2023 10:28:52 -0800 Message-ID: To: Dan Cross Content-Type: multipart/alternative; boundary="000000000000e96b7605f1745bf5" Message-ID-Hash: BFM5P4QDXTZACUJWIAZOIGM6W3UY4GMC X-Message-ID-Hash: BFM5P4QDXTZACUJWIAZOIGM6W3UY4GMC X-MailFrom: rminnich@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-tuhs.tuhs.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Bakul Shah , The Eunuchs Hysterical Society X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [TUHS] Re: A few comments on porting the Bourne shell List-Id: The Unix Heritage Society mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --000000000000e96b7605f1745bf5 Content-Type: text/plain; charset="UTF-8" What I see so far from this discussion: Ted has written a lot of useful scripts, but they are explicitly for one shell (bash) on one kernel (linux). I.e. portability is not a concern. People immediately pointed out how easy it is to write non-portable shell scripts, and others commented that it does not matter (to them). Kernel portability matters to me. So does code that works without regard to the shell someone is using. So does robust error handling. So does math. These are all things that, in my experience, rule against complex shell scripts. I still prefer Go as my scripting language, but we all have our preferences. And, yes, Go gets wordy, but it's a price I'm happy to pay for good error handling. I much prefer an error message to 100 lines of python backtrace. On Wed, Jan 4, 2023 at 8:17 AM Dan Cross wrote: > On Tue, Jan 3, 2023 at 11:16 PM Bakul Shah wrote: > > On Jan 3, 2023, at 7:31 PM, Dan Cross wrote: > > > On Tue, Jan 3, 2023 at 10:22 PM John Cowan wrote: > > >> Making shell scripts portable means not using pipelines, because > given "foo | bar", kshNN and zsh execute foo in a subshell and bar in the > top-level shell, whereas in other shells, both foo and bar execute in > subshells. (For this reason, Posix allows either behavior.) Not having > pipelines is a pretty drastic limitation. > > > > > > This came up at work just the other day: > > > > > > echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer > > > echo $bummer > > > > > > The behavior varies between ksh, zsh, bash, sh. Yay. > > > > On this example sh, zsh, bash behave the same way on > > freebsd. Rather than ban |, I think the lesson is to > > *avoid* builtin commands in a pipeline that can affect > > shell's environment. I only write /bin/sh scripts in > > any case. > > Interesting. In my testing, `bash` was the odd man out: > > : doctor; zsh > : doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer > echo $bummer > > hi > : doctor; > : doctor; bash > : doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer > echo $bummer > > : doctor; > exit > : doctor; ksh > : doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer > : doctor; echo $bummer > hi > : doctor; > : doctor; sh > : doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer > : doctor; echo $bummer > hi > : doctor; > : doctor; > > That's on illumos. > > On OpenBSD, neither bash, ksh, or sh produce output, while zsh does. I > suspect ksh is pdksh and sh is a link to ksh there, though. ksh93 > gives "hi". > > On FreeBSD, neither bash nor sh produce "hi", but zsh and ksh93 do. > Same on DragonFly, macOS and Arch Linux. On 7th edition, I only tried > sh; empty output. 4.3BSD gives empty output for /bin/sh. For kicks, > neither tcsh nor csh understand `read`; I don't think that *csh has a > read-like builtin. > > This is, of course, a silly example. Most script authors would do > something like: > > bummer=`echo ' hi ' | sed 's/^ *//;s/ *$//'` > > Or, perhaps even: > > bummer=$(echo ' hi ' | sed 's/^ *//;s/ *$//') > > Life's too short and at this point I prefer the latter, but more often > than not my fingers are wired for the former. > > > It is really unfortunate that infix | is so beguiling! > > Except for that a Lisp or Scheme based shell would've > > been fine and dandy! :-)/2 > > Whatever happened to `es` ? I guess it died on the vine. It seemed > like a nifty idea. > > I made a concerted effort to use `rc` as my shell on Unix for a little > while. Without all the supporting plan9 machinery, though, I gave up. > Minimalism is great in an environment that can augment it with useful > functionality; outside of that environment, it can be kind of a pain > for work-a-day use. > > - Dan C. > --000000000000e96b7605f1745bf5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
What I see so far from this discussion: Ted has written a = lot of useful scripts, but they are explicitly for one shell (bash) on one = kernel (linux). I.e. portability is not a concern.

Peopl= e immediately=C2=A0pointed out how easy it is to write non-portable shell s= cripts, and others commented that it does not matter (to them).
<= br>
Kernel portability matters to me. So does code that works wit= hout regard to the shell someone is using. So does robust error handling. S= o does math. These are all things that, in my experience, rule against comp= lex shell scripts.=C2=A0

I still prefer Go as my s= cripting language, but we all have our preferences. And, yes, Go gets wordy= , but it's a price I'm happy to pay for good error handling. I much= prefer an error message to 100 lines of python backtrace.

<= div class=3D"gmail_quote">
On Wed, Jan= 4, 2023 at 8:17 AM Dan Cross <cross= d@gmail.com> wrote:
On Tue, Jan 3, 2023 at 11:16 PM Bakul Shah <bakul@iitbombay.org> wrote:<= br> > On Jan 3, 2023, at 7:31 PM, Dan Cross <crossd@gmail.com> wrote:
> > On Tue, Jan 3, 2023 at 10:22 PM John Cowan <cowan@ccil.org> wrote:
> >> Making shell scripts portable means not using pipelines, beca= use given "foo | bar", kshNN and zsh execute foo in a subshell an= d bar in the top-level shell, whereas in other shells, both foo and bar exe= cute in subshells.=C2=A0 (For this reason, Posix allows either behavior.)= =C2=A0 Not having pipelines is a pretty drastic limitation.
> >
> > This came up at work just the other day:
> >
> > echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer=
> > echo $bummer
> >
> > The behavior varies between ksh, zsh, bash, sh. Yay.
>
> On this example sh, zsh, bash behave the same way on
> freebsd. Rather than ban |, I think the lesson is to
> *avoid* builtin commands in a pipeline that can affect
> shell's environment. I only write /bin/sh scripts in
> any case.

Interesting. In my testing, `bash` was the odd man out:

: doctor; zsh
: doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer=
echo $bummer

hi
: doctor;
: doctor; bash
: doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer=
echo $bummer

: doctor;
exit
: doctor; ksh
: doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer=
: doctor; echo $bummer
hi
: doctor;
: doctor; sh
: doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer=
: doctor; echo $bummer
hi
: doctor;
: doctor;

That's on illumos.

On OpenBSD, neither bash, ksh, or sh produce output, while zsh does. I
suspect ksh is pdksh and sh is a link to ksh there, though. ksh93
gives "hi".

On FreeBSD, neither bash nor sh produce "hi", but zsh and ksh93 d= o.
Same on DragonFly, macOS and Arch Linux. On 7th edition, I only tried
sh; empty output. 4.3BSD gives empty output for /bin/sh. For kicks,
neither tcsh nor csh understand `read`; I don't think that *csh has a read-like builtin.

This is, of course, a silly example. Most script authors would do
something like:

=C2=A0 =C2=A0 bummer=3D`echo ' hi ' | sed 's/^ *//;s/ *$//'= `

Or, perhaps even:

=C2=A0 =C2=A0 bummer=3D$(echo ' hi ' | sed 's/^ *//;s/ *$//'= ;)

Life's too short and at this point I prefer the latter, but more often<= br> than not my fingers are wired for the former.

> It is really unfortunate that infix | is so beguiling!
> Except for that a Lisp or Scheme based shell would've
> been fine and dandy! :-)/2

Whatever happened to `es` ? I guess it died on the vine. It seemed
like a nifty idea.

I made a concerted effort to use `rc` as my shell on Unix for a little
while. Without all the supporting plan9 machinery, though, I gave up.
Minimalism is great in an environment that can augment it with useful
functionality; outside of that environment, it can be kind of a pain
for work-a-day use.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 - Dan C.
--000000000000e96b7605f1745bf5--