[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: |
ikhxcsz7y xmbott |
Subject: |
Re: using a variable from global scope or checking whether it is local to some scope |
Date: |
Thu, 19 Oct 2023 23:57:45 +0200 |
On Thu, Oct 19, 2023, 23:42 Christoph Anton Mitterer <calestyo@scientia.org>
wrote:
> 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?
>
1 i mean when u need a change of local to global back u add this to the
code ..
2 it seems me bug in bash :
~ $ ( declare -g a ; a=2 ; declare -p a ; declare a ; a=3 ; declare -p a ;
declare -g a ; declare -p a ; a=4 ; declare -p a )
declare -- a="2"
declare -- a="3"
declare -- a="3"
declare -- a="4"
the third is from local back global , but it says value of local ( 3 ) and
not original value ( 2 )
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.
>
>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: using a variable from global scope or checking whether it is local to some scope,
ikhxcsz7y xmbott <=