On Wed, Jan 04, 2023 at 12:21:27AM -0600, Carlos Prieto López wrote:
> Description:
> Errors are ignored when a command with error is assigned to a local
> variable on the same line of declaration.
>
> f(){
> return 1
> }
>
> g(){
> local v=`f`
> }
> g && echo g
> the output is 'g', but I believe there should be no output
The "local" command has its own exit status, and this masks the exit
status of the command substitution.
You've already found a workaround:
> i(){
> local v
> v=`f`
> }
Just continue using that. This isn't a bug in bash, and it won't be
changed.
(While you're at it, you might want to switch from the obsolete backtick
syntax to the preferred $() syntax for command substitutions.)