2025年8月28日(木) 17:29 Martin D Kealey <mar...@kurahaupo.gen.nz>:
> On Wed, 27 Aug 2025 at 15:16, Koichi Murase <myoga.mur...@gmail.com> wrote:
>>   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)?

Or `local -I BASHOPTS' (as `local -' is for preserving `$-'). I
actually think it would be very useful in general.

However, in the present context, even with such a feature, we still
cannot simply write

  foo=$(some_command ...)

but we need to write

  local -
  shopt -s cmdsubst_trailing_nls
  foo=$(some_command ...)

in the general context where `cmdsubst_trailing_nls' may be changed by
others. Also, existing codebases of Bash frameworks need to be updated
to include

  local -
  shopt -u cmdsubst_trailing_nls

at the beginning of every function using any command substitutions.
It's simpler than « local saved=$(...) ... eval -- "$saved" », but the
fact that existing script codebases need global updates is unchanged.

--
Koichi

Reply via email to