bug-bash
[Top][All Lists]
Advanced

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

Re: declare -g -x in function does not get exported in this script - not


From: Greg Wooledge
Subject: Re: declare -g -x in function does not get exported in this script - not on ubunto 20.04 and centos 8
Date: Wed, 2 Jun 2021 21:04:06 -0400

On Wed, Jun 02, 2021 at 03:54:34PM -0600, vbox@it4us.top wrote:
> --------------------------first script where declare -x -g works
> bar(){
> 
>       [[ $cnt == 1 ]] && declare -g -x nestedbug="not a nested variable-bug 
> !!"
> }
> 
> foo(){
>       [[ $cnt == 1 ]] && bar && echo ${nestedbug:?"variable should be  shown"}
> }
> foo

In this script, you're calling foo in the main shell process, and foo
calls bar, which sets the variable.  All of this takes place within
a single process.

> --------------------------begin of not working script 
> ------------------------------------
> doOptions(){
>       declare -g -x nestedbug="NOT BUG"
>       return 0 
> }
> doRun(){
> run=$( doOptions $* )

... and here, you are calling doOptions inside a subshell.

The variables that you create within the subshell vanish when the
subshell does.  Even if you export them.

In the future, please try to create minimal examples that reproduce
the problem.  I had to delete a *lot* of extraneous code.



reply via email to

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