Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH?] Nofork and removing newlines
- X-seq: zsh-workers 52697
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH?] Nofork and removing newlines
- Date: Wed, 6 Mar 2024 19:43:13 +0000
- Archived-at: <https://zsh.org/workers/52697>
- In-reply-to: <CAH+w=7Yb6_eULBq6Ez6pEhtUXOqErr+aDL2BDi7zyxr8QpsTiw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- References: <CAH+w=7aFJH-5GAu6puszGKvjqN-w0sPCi6v-vGPauDHVujDnag@mail.gmail.com> <20240305065606.ccr2ieheahslcpye@chazelas.org> <CAH+w=7Yb6_eULBq6Ez6pEhtUXOqErr+aDL2BDi7zyxr8QpsTiw@mail.gmail.com>
2024-03-05 14:48:00 -0800, Bart Schaefer:
[...]
> The suggested change would provide
> $(...)-like behavior for the usual case and a simple way to keep the
> newline(s) in the less-usual cases.
[...]
For reference, some other shells that can keep trailing newline
in command subtitution:
rc:
whole_output = ``(){cmd and its args}
fish:
set whole_output (cmd and its args | string collect -aN)
(-aN short for --allow-empty --no-trim-newlines).
fish's command substitution ( (...) and also $(...) including
inside "..." in recent versions) doesn't fork so is closer to
ksh93's ${ cmd; } than ksh86's $(...)
POSIX/Korn-like shells:
I'm sure everyone will have their own variant, but
get_whole_output() {
eval "
$1"'=$(shift; "$@"; ret=$?; echo .; exit "$ret")
set -- "$1" "$?"
'"$1"'=${'"$1"'%.}
return "$2"'
}
get_whole_output whole_output cmd and its args
(bearing in mind that there aren't many characters beside .
that you can use safely there as it's important its encoding
can't be found in the encoding of other characters.
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author