bug-bash
[Top][All Lists]
Advanced

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

Re: Vars not set when sourcing w/ abs path, set -a


From: Greg Wooledge
Subject: Re: Vars not set when sourcing w/ abs path, set -a
Date: Tue, 27 Jul 2021 21:37:36 -0400

On Tue, Jul 27, 2021 at 11:42:02PM +0000, Van Klaveren, Brian N. wrote:
> [bash-test@227f958499c1 ~]$ cat sourceme
> #!/bin/bash
> FOO=bar
> FOO=bar2
> set -a
> env | grep FOO

You probably want to put set -a at the top, before the variables are
set.  The -a flag isn't retroactive.  It only applies to variables
that are set *while* it's turned on.

The typical ways that set -a is used are:

1) Around a block of variable assignments within a script, in order to
   avoid having to type "export" several times.

2) Right before sourcing (dotting in) a second file which contains only
   variable assignments, so that all of those variable assignments are
   copied to the environment, without having to modify the sourced file.



reply via email to

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