Re: Problems encountered with printing local variables in the new command substitution in bash 5.3

Greg Wooledge <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <[email protected]>
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.)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.