On Jan 3, 2023, at 7:31 PM, Dan Cross <crossd(a)gmail.com> wrote:
On Tue, Jan 3, 2023 at 10:22 PM John Cowan <cowan(a)ccil.org> 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.
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