Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Export multiple environment variables with the dependency relationships at once.

9 views
Skip to first unread message

hongy...@gmail.com

unread,
Aug 3, 2022, 1:22:49 AM8/3/22
to
I set the environment variables as follows for my customized script/program/tool as follows:

script_realdirname=/path/to/some/script
export ISODATA=$script_realdirname/iso/
export PATH=$ISODATA:$PATH

If I combine the above last two lines into the following, the PATH export does not seem to take effect:

export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH

Any hints for this problem?

Regards,
Zhao

Bit Twister

unread,
Aug 3, 2022, 2:26:30 AM8/3/22
to
Not me since it appears to work for me.

[bittwister@wb ~]$ script_realdirname=/path/to/some/script
[bittwister@wb ~]$ export ISODATA=$script_realdirname/iso/
[bittwister@wb ~]$ export PATH=$ISODATA:$PATH
[bittwister@wb ~]$ export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH
[bittwister@wb ~]$ echo $PATH
/path/to/some/script/iso/:/path/to/some/script/iso/:/home/bittwister/local/work:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/lib64/qt5/bin:/usr/lib64/qt4/bin:/local/bin:/usr/local/games:/usr/games:/home/bittwister/local/bin:/local/bin

hongy...@gmail.com

unread,
Aug 3, 2022, 2:57:14 AM8/3/22
to
Thank you for your confirmation. It seems that I messed up a few things at the time, and it actually works as you described.

Best,
Zhao

Keith Thompson

unread,
Aug 3, 2022, 11:49:42 AM8/3/22
to
It works for you because you *added* the double export command after
executing the export ISODATA=... and export PATH=... commands.

If you *replace* the two export commands with a single one, then of
course the ISODATA hasn't been set yet, and '$ISODATA' doesn't expand.

$ export ZERO=ONE TWO=$ZERO
bash: ZERO: unbound variable
$

(I have `set -o nounset`.)

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Janis Papanagnou

unread,
Aug 3, 2022, 12:00:24 PM8/3/22
to
On 03.08.2022 17:49, Keith Thompson wrote:
> Bit Twister <BitTw...@mouse-potato.com> writes:
>> On Tue, 2 Aug 2022 22:22:46 -0700 (PDT), hongy...@gmail.com wrote:
>>> I set the environment variables as follows for my customized script/program/tool as follows:
>>>
>>> script_realdirname=/path/to/some/script
>>> export ISODATA=$script_realdirname/iso/
>>> export PATH=$ISODATA:$PATH
>>>
>>> If I combine the above last two lines into the following, the PATH export does not seem to take effect:
>>>
>>> export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH
>>>
>>> Any hints for this problem?
>>
>> Not me since it appears to work for me.
>>
>> [bittwister@wb ~]$ script_realdirname=/path/to/some/script
>> [bittwister@wb ~]$ export ISODATA=$script_realdirname/iso/
>> [bittwister@wb ~]$ export PATH=$ISODATA:$PATH
>> [bittwister@wb ~]$ export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH
>> [bittwister@wb ~]$ echo $PATH
>> /path/to/some/script/iso/:/path/to/some/script/iso/:/home/bittwister/local/work:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/lib64/qt5/bin:/usr/lib64/qt4/bin:/local/bin:/usr/local/games:/usr/games:/home/bittwister/local/bin:/local/bin
>
> It works for you because you *added* the double export command after
> executing the export ISODATA=... and export PATH=... commands.

It might also work for him because he might be using ksh.
In other words; it works for me.

But chances are high that the OP is using bash.

Janis

Kaz Kylheku

unread,
Aug 3, 2022, 1:03:33 PM8/3/22
to
On 2022-08-03, hongy...@gmail.com <hongy...@gmail.com> wrote:
> I set the environment variables as follows for my customized script/program/tool as follows:
>
> script_realdirname=/path/to/some/script
> export ISODATA=$script_realdirname/iso/
> export PATH=$ISODATA:$PATH
>
> If I combine the above last two lines into the following, the PATH export does not seem to take effect:
>
> export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH

export effectively has parallel binding semantics, because the
values being assigned to to the variables are expanded strings,
and the expansion takes place before export executes.

Example: exchange the values of x and y:

$ x=x
$ y=y
$ export x=$y y=$x
$ echo $x
y
$ echo $y
x

The export command first expands to.

export x=y y=x

This expansion no longer contains any variables to be expanded; its
arguments are pure text. But the export command has not yet
executed, so x and y still have their original values.

So when export executes, x is set to "y" and y to "x".
Those new values are no longer being calculated from prior
values. All the use of prior values took place when the
command line was expanded.


--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Bit Twister

unread,
Aug 3, 2022, 5:45:22 PM8/3/22
to
On Wed, 3 Aug 2022 18:00:06 +0200, Janis Papanagnou wrote:
> On 03.08.2022 17:49, Keith Thompson wrote:
>> Bit Twister <BitTw...@mouse-potato.com> writes:
>>> On Tue, 2 Aug 2022 22:22:46 -0700 (PDT), hongy...@gmail.com wrote:
>>>> I set the environment variables as follows for my customized script/program/tool as follows:
>>>>
>>>> script_realdirname=/path/to/some/script
>>>> export ISODATA=$script_realdirname/iso/
>>>> export PATH=$ISODATA:$PATH
>>>>
>>>> If I combine the above last two lines into the following, the PATH export does not seem to take effect:
>>>>
>>>> export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH
>>>>
>>>> Any hints for this problem?
>>>
>>> Not me since it appears to work for me.
>>>
>>> [bittwister@wb ~]$ script_realdirname=/path/to/some/script
>>> [bittwister@wb ~]$ export ISODATA=$script_realdirname/iso/
>>> [bittwister@wb ~]$ export PATH=$ISODATA:$PATH
>>> [bittwister@wb ~]$ export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH
>>> [bittwister@wb ~]$ echo $PATH
>>> /path/to/some/script/iso/:/path/to/some/script/iso/:/home/bittwister/local/work:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/lib64/qt5/bin:/usr/lib64/qt4/bin:/local/bin:/usr/local/games:/usr/games:/home/bittwister/local/bin:/local/bin
>>
>> It works for you because you *added* the double export command after
>> executing the export ISODATA=... and export PATH=... commands.
>
> It might also work for him because he might be using ksh.

But I am not.

$ echo $SHELL
/bin/bash

$ ls -l /bin/bash
-rwxr-xr-x 1 root root 947520 Dec 30 2020 /bin/bash

> In other words; it works for me.

$ $SHELL --version
GNU bash, version 5.1.4(1)-release (x86_64-mageia-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Janis Papanagnou

unread,
Aug 3, 2022, 7:15:39 PM8/3/22
to
On 03.08.2022 23:45, Bit Twister wrote:
> On Wed, 3 Aug 2022 18:00:06 +0200, Janis Papanagnou wrote:
>> On 03.08.2022 17:49, Keith Thompson wrote:
>>>
>>> It works for you because [...]
>>
>> It might also work for him because he might be using ksh.
>
> But I am not.

The emphasis was not on "you" (personally) but on the fact that
the shell was unspecified and other shells behave differently.

As Keith already pointed out, with the code "you" (personally)
tried you wouldn't observe the problem in the first place.

Janis

hongy...@gmail.com

unread,
Aug 3, 2022, 9:09:23 PM8/3/22
to
On Wednesday, August 3, 2022 at 11:49:42 PM UTC+8, Keith Thompson wrote:
> Bit Twister <BitTw...@mouse-potato.com> writes:
> > On Tue, 2 Aug 2022 22:22:46 -0700 (PDT), hongy...@gmail.com wrote:
> >> I set the environment variables as follows for my customized script/program/tool as follows:
> >>
> >> script_realdirname=/path/to/some/script
> >> export ISODATA=$script_realdirname/iso/
> >> export PATH=$ISODATA:$PATH
> >>
> >> If I combine the above last two lines into the following, the PATH export does not seem to take effect:
> >>
> >> export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH
> >>
> >> Any hints for this problem?
> >
> > Not me since it appears to work for me.
> >
> > [bittwister@wb ~]$ script_realdirname=/path/to/some/script
> > [bittwister@wb ~]$ export ISODATA=$script_realdirname/iso/
> > [bittwister@wb ~]$ export PATH=$ISODATA:$PATH
> > [bittwister@wb ~]$ export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH
> > [bittwister@wb ~]$ echo $PATH
> > /path/to/some/script/iso/:/path/to/some/script/iso/:/home/bittwister/local/work:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/lib64/qt5/bin:/usr/lib64/qt4/bin:/local/bin:/usr/local/games:/usr/games:/home/bittwister/local/bin:/local/bin
> It works for you because you *added* the double export command after
> executing the export ISODATA=... and export PATH=... commands.
>
> If you *replace* the two export commands with a single one, then of
> course the ISODATA hasn't been set yet, and '$ISODATA' doesn't expand.
>
> $ export ZERO=ONE TWO=$ZERO
> bash: ZERO: unbound variable
> $

Here's my test:

werner@X10DAi-00:~$ export ZERO=ONE TWO=$ZERO
werner@X10DAi-00:~$ echo $TWO

werner@X10DAi-00:~$ echo $ZERO
ONE

hongy...@gmail.com

unread,
Aug 3, 2022, 9:18:04 PM8/3/22
to
Thank you for your wonderful analysis and example.

Zhao

hongy...@gmail.com

unread,
Aug 3, 2022, 9:18:50 PM8/3/22
to
On Thursday, August 4, 2022 at 12:00:24 AM UTC+8, Janis Papanagnou wrote:
> On 03.08.2022 17:49, Keith Thompson wrote:
> > Bit Twister <BitTw...@mouse-potato.com> writes:
> >> On Tue, 2 Aug 2022 22:22:46 -0700 (PDT), hongy...@gmail.com wrote:
> >>> I set the environment variables as follows for my customized script/program/tool as follows:
> >>>
> >>> script_realdirname=/path/to/some/script
> >>> export ISODATA=$script_realdirname/iso/
> >>> export PATH=$ISODATA:$PATH
> >>>
> >>> If I combine the above last two lines into the following, the PATH export does not seem to take effect:
> >>>
> >>> export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH
> >>>
> >>> Any hints for this problem?
> >>
> >> Not me since it appears to work for me.
> >>
> >> [bittwister@wb ~]$ script_realdirname=/path/to/some/script
> >> [bittwister@wb ~]$ export ISODATA=$script_realdirname/iso/
> >> [bittwister@wb ~]$ export PATH=$ISODATA:$PATH
> >> [bittwister@wb ~]$ export ISODATA=$script_realdirname/iso/ PATH=$ISODATA:$PATH
> >> [bittwister@wb ~]$ echo $PATH
> >> /path/to/some/script/iso/:/path/to/some/script/iso/:/home/bittwister/local/work:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/lib64/qt5/bin:/usr/lib64/qt4/bin:/local/bin:/usr/local/games:/usr/games:/home/bittwister/local/bin:/local/bin
> >
> > It works for you because you *added* the double export command after
> > executing the export ISODATA=... and export PATH=... commands.
> It might also work for him because he might be using ksh.
> In other words; it works for me.
>
> But chances are high that the OP is using bash.

Yes. Exactly.

Zhao
0 new messages