• Export multiple environment variables with the dependency relationships

    From hongyi.zhao@gmail.com@21:1/5 to All on Tue Aug 2 22:22:46 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bit Twister@21:1/5 to hongy...@gmail.com on Wed Aug 3 01:26:22 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Bit Twister on Tue Aug 2 23:57:11 2022
    On Wednesday, August 3, 2022 at 2:26:30 PM UTC+8, Bit Twister wrote:
    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

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Keith Thompson on Wed Aug 3 18:00:06 2022
    On 03.08.2022 17:49, Keith Thompson wrote:
    Bit Twister <BitTwister@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


    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`.)


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to Bit Twister on Wed Aug 3 08:49:24 2022
    Bit Twister <BitTwister@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
    $

    (I have `set -o nounset`.)

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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to hongy...@gmail.com on Wed Aug 3 17:03:28 2022
    On 2022-08-03, hongy...@gmail.com <hongyi.zhao@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bit Twister@21:1/5 to Janis Papanagnou on Wed Aug 3 16:45:01 2022
    On Wed, 3 Aug 2022 18:00:06 +0200, Janis Papanagnou wrote:
    On 03.08.2022 17:49, Keith Thompson wrote:
    Bit Twister <BitTwister@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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Bit Twister on Thu Aug 4 01:15:34 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Keith Thompson on Wed Aug 3 18:09:19 2022
    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


    (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 */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Janis Papanagnou on Wed Aug 3 18:18:47 2022
    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


    Janis

    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`.)


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Kaz Kylheku on Wed Aug 3 18:18:00 2022
    On Thursday, August 4, 2022 at 1:03:33 AM UTC+8, Kaz Kylheku wrote:
    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.

    Thank you for your wonderful analysis and example.

    Zhao

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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)