Configuration Information [Automatically generated, do not change]:

Machine: x86_64

OS: linux-gnu

Compiler: gcc

Compilation CFLAGS: -g -O2

uname output: Linux fs 6.5.11-7-pve #1 SMP PREEMPT_DYNAMIC PMX 6.5.11-7
(2023-12-05T09:44Z) x86_64 GNU/Linux

Machine Type: x86_64-pc-linux-gnu


Bash Version: 5.2

Patch Level: 21

Release Status: release


Description:

       `declare -p` loses the global flag passed to variable/array on
definition.

       I think this behaviour is reasonable, but sometimes I need to
save/restore

       Global variables in the function. Unfortunately when I source saved

       variables from a function the variables are scoped to that function.

       Could you please add the ability to display all the variables as
global

       when using '-g' along with '-p' option? No internal checks needed,
just

       Put the '-g' flag when displaying each variable definition requested.


Repeat-By:

       # define a variable:

       declare -g A=33

       # display it

       declare -p A

       declare -- A="33"


       # I would like to be able to do this:

       declare -gp A

       # expected result:

       declare -g A="33"

       # unfortunately, currently it is the same as `declare -p`

Reply via email to