Can some one give an example where declare -x
would be useful ?
Use declare -x
when you want to pass a variable to a different program, but don't want the variable to be used in global scope of the parent shell (i.e. when declaring inside a function).
From the bash help:
When used in a function,
declare
makes NAMEs local, as with thelocal
command. The-g
option suppresses this behavior.
-x to make NAMEs export
Using
+
instead of-
turns off the given attribute.
So declare -gx NAME=X
will effectively behave the same as export NAME=X
, but declare -x
does not when the declare statements are inside functions.
declare -x FOO
is the same as export FOO
. It "exports" the FOO
variable as an environment variable, so that programs you run from that shell session would see it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With