Re: [PATCH] Add shopts for trailing newlines in command substitution and
From:
Martin D Kealey
Subject:
Re: [PATCH] Add shopts for trailing newlines in command substitution and here strings
Date:
Thu, 28 Aug 2025 18:29:29 +1000
On Wed, 27 Aug 2025 at 15:16, Koichi Murase <myoga.murase@gmail.com> wrote:
>
> However, this isn't true. With these features implemented as shell
> options, in general, one actually needs to write it in the following
> way:
>
> local saved=$(shopt -p cmdsubst_trailing_nls) # (assume we are in a
> function)
> shopt -s cmdsubst_trailing_nls
> foo=$(some_command ...)
> eval -- "$saved"
Couldn't we just dictate that "local -" saves all set -o and shopt settings
(or at least all new ones going forward)?
So then it'd be just:
fn() {
local -
shopt -s cmdsubst_trailing_nls
foo=$( some_command … )
}
Or maybe it's time to consider:
fn() {
local -O cmdsubst_trailing_nls=1
foo=$( some_command … )
}
-Martin