bug-bash
[Top][All Lists]
Advanced

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

Re: Problems encountered with printing local variables in the new comman


From: Greg Wooledge
Subject: Re: Problems encountered with printing local variables in the new command substitution in bash 5.3
Date: Tue, 6 Jan 2026 22:49:02 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

On Wed, Jan 07, 2026 at 10:15:55 +0800, 王伟 wrote:
>     local all_var_info=${ local;}
>     declare -p all_var_info

> test_case6 ret----------
> declare -- all_var_info=""

The man page says:

       This  type of command substitution superficially resembles executing an
       unnamed shell function: local variables are created  as  when  a  shell
       function  is  executing,  and the return builtin forces command to com-
       plete; however, the rest of the execution  environment,  including  the
       positional parameters, is shared with the caller.

Since bash provides no way to print the local variables of your caller,
the curly-brace command substitution is simply not what you want here.
Continue using $( ) instead, since that does what you need.  (Or write
local's output to a temp file and read it back in.  That also works.)



reply via email to

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