[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to tell if a variable is global or not within a function?
From: |
Alex fxmbsw7 Ratchev |
Subject: |
Re: How to tell if a variable is global or not within a function? |
Date: |
Thu, 10 Mar 2022 09:16:42 +0100 |
i guess on mixed usage u have to specift -g or not again
On Thu, Mar 10, 2022, 05:49 Peng Yu <pengyu.ut@gmail.com> wrote:
> I can test if a variable defined in a function is global or not like
> this. But it is not done within a function. Is there a way to tell if
> a variable is global or not within a function via declare -p?
>
> $ function f { declare -g x; declare -p x; }
> $ f
> declare -- x
> $ declare -p x
> declare -- x
> $ function g { declare y; declare -p y; }
> $ g
> declare -- y
> $ declare -p y
> -bash: declare: y: not found
>
> --
> Regards,
> Peng
>
>