bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add shopts for trailing newlines in command substitution and


From: Koichi Murase
Subject: Re: [PATCH] Add shopts for trailing newlines in command substitution and here strings
Date: Fri, 29 Aug 2025 00:17:44 +0900

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

[Prev in Thread] Current Thread [Next in Thread]