help-bash
[Top][All Lists]
Advanced

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

Re: using a variable from global scope or checking whether it is local t


From: Christoph Anton Mitterer
Subject: Re: using a variable from global scope or checking whether it is local to some scope
Date: Thu, 19 Oct 2023 23:42:10 +0200
User-agent: Evolution 3.50.0-1

Hey Alex.

On Thu, 2023-10-19 at 22:17 +0200, alex xmb sw ratchev wrote:
> another answer
> in ur code , force global / local whenever u need it
> 
> ~ $ ( declare -g a ; a=2 ; declare -p a ; declare a ; declare -p a ;
> a=3 )
> declare -- a="2"
> declare -- a="2"
> ~ $
> 
> sadly i didnt find difference there
> but just declare -g or non -g when u need

I don't understand how this should help?
Yes it allows me to set the global one, but I cannot expand it?


a=global

other()
{
   local a=from_other
   mine
   echo $a
}

mine()
{
   echo $a
   ( declare -g a ; echo $a; declare -p a )
   
}

echo $a
other


gives:
global
from_other
from_other
declare -- a="from_other"
from_other



Cheers,
Chris.



reply via email to

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