On Wed, Jun 02, 2021 at 03:54:34PM -0600, v...@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