How to change Linux $PATH

Help
2009-04-09
2012-08-14
  • How does one change the Linux $PATH wiith a Rexx program (so that the change persists)?

    I though the VALUE function would do that, but although this program:

    / Change Linux $PATH /

    say value("PATH",,"ENVIRONMENT")
    say value("PATH","nonsense","ENVIRONMENT")
    say value("PATH",,"ENVIRONMENT")

    shows:

    rexx ~/rx/t3
    /opt/kde3/bin:/usr/bin:/bin:/usr/local/bin:/usr/games:/usr/lib/qt4/bin
    /opt/kde3/bin:/usr/bin:/bin:/usr/local/bin:/usr/games:/usr/lib/qt4/bin
    nonsense

    which at first sight seems to have done the trick, but then:

    echo $PATH
    /opt/kde3/bin:/usr/bin:/bin:/usr/local/bin:/usr/games:/usr/lib/qt4/bin

    shows that the change did not survive exit from the REXX program, suggesting that VALUE is not the correct vehicle.

    How does a Rexx program change $PATH so that the change persists?

    I am using:

    rexx -v
    Open Object Rexx Interpreter Version 3.1.2 for LINUX
    Build date: Mar 11 2008
    Copyright (c) IBM Corporation 1995, 2004.
    Copyright (c) RexxLA 2005-2007.

    Maurice Batey (Retired in Surrey, UK)

     
    • > > "Is there no way a Rexx program can pass a result back to the calling bash process?"

      > Not if bash doesn't want it to. <grin> Sure there are ways to do what you want.

      One way could be to run REXX with a leading ". " (dot, space).

      ulmo:/opt/bsf4rexx # . ./test.rex

      with test.rex :

      !/usr/bin/rexx

      export "PATHX=xxx"

      and this sets PATHX in the current session (I don't really understand why).

      Cheers, Uli

       
    • Mark Miesfeld
      Mark Miesfeld
      2009-04-09

      "How does one change the Linux $PATH wiith a Rexx program (so that the change persists)?"

      The basic answer is you can't. You can't in Windows either. In general, a child process can not change the environment of its parent.

      You can change the path in the child process, (your Rexx program executing.) But then when rexx exits, you are back in the parent process and the environment of the parent is unchanged by the child.

       
    • OK - it's as I feared! Thank you.

      I had hoped to be able to use Rexx to do certain system tidying up (removing redundant addresses from $PATH, in this case), but I guess I'll just have to abandon that and descend into 'bash'....

      But I am disappointed that Rexx cannot change values in the immediately calling level, i.e. the level from which the Rexx program was invoked, if that level could sanction that.

       
    • Maurice Batey
      Maurice Batey
      2009-04-10

      Posted by Mark Miesfeld (miesfeld) - 2009-04-09 22:03:

      > You can change the path in the child process, (your Rexx program executing.) > But then when rexx exits, you are back in the parent process and the
      > environment of the parent is unchanged by the child.

      Well, that's the same as when a bash program is called from a Linux bash process, except that the program can be called with "source <progname>", so that the code of the program is included (in the old Assembler sense) and executed as part of the parent process.

      Is there no way a Rexx program can pass a result back to the calling bash process?

      Presumably it could write the result into an agreed file (but how does Rexx cope with Linux permissions there?).

      Is there some communications buffer where the result could be placed?

      Can a Rexx program be called - from a Linux bash process - as a procedure, e.g.:

      echo [rexx <rexxprogname>]

       
    • Mark Miesfeld
      Mark Miesfeld
      2009-04-10

      "Well, that's the same as when a bash program is called from a Linux bash process, except that the program can be called with "source <progname>", so that the code of the program is included (in the old Assembler sense) and executed as part of the parent process."

      No, it is not really the same at all. source is a bash command that tells bash to read and execute the bash commands in progname in the current shell environment.

      When you type the name of an executable file on the bash command line, bash tries to find an executable file in the path that matches the name you typed and then tries to execute it in a separate execution environment.

      "Is there no way a Rexx program can pass a result back to the calling bash process?"

      Not if bash doesn't want it to. <grin> Sure there are ways to do what you want. But, you need to rewrite bash to do them, not rewrite ooRexx.

      bash executes rexx in a separate environment specifically because bash doesn't want rexx to change its environment.

      bash does allow an executable to pass back a result, it allows the return of a numeric return code.

      --
      Mark Miesfeld

       
    • > source is a bash command that tells bash to read and execute the bash commands in > progname in the current shell environment.

      > When you type the name of an executable file on the bash command line, bash tries to > find an executable file in the path that matches the name you typed and then tries to
      > execute it in a separate execution environment.

      Yes, indeed, but the point I was trying to make was that the latter case is the same as with a call of Rexx, but when invoking Rexx there is no 'source' facility to execute it at the parent level, as in the first case.