Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    global environment variables

    I have a vendor-provided shell script that I'm executing in Korn shell. It simply sets some environment variables. The variables that are set do not remain persistent outside of the script. So I decided to do some testing by creating a simple script. The contents of are:

    export MY_DIR=/apps/inserver6

    I change the permissions on the file so that it can be executed, then execute it. However, the following results in null output:

    echo $MY_DIR

    What am I missing? Any help would be greatly appreciated.


  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    The variable MY_DIR is set in the context of that script´s process.
    And it is confined to it.

    So you call the script, a process is created, the variable gets set and then the script ends and the process dies.
    And with it the variable.

    To set variables for the current process, you need to source that script.
    In bash, this can be done with the dot command.
    In korn shell it is probably also the dot command, but in doubt consult the man page.
    You must always face the curtain with a bow.

  3. #3
    Got it. Instead of this:


    I had to run this:

    . ./

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts