[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Vars not set when sourcing w/ abs path, set -a
From: |
Van Klaveren, Brian N. |
Subject: |
Re: Vars not set when sourcing w/ abs path, set -a |
Date: |
Wed, 28 Jul 2021 05:45:28 +0000 |
Ah that's it. That totally makes sense in retrospect, this is because I'm
basically sourcing the `set -a` so the second time it's set, but also the first
time `env` doesn't see the local.
(2) is what I was trying to achieve.
Thanks! Sorry for the noise.
Brian
> On Jul 27, 2021, at 6:37 PM, Greg Wooledge <greg@wooledge.org> wrote:
>
> 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.