Find the answer to your Linux question:
Results 1 to 3 of 3
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    25

    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 df.sh 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.

    Thanks,
    Dave

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,380
    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.
    Code:
    . df.sh
    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
    Just Joined!
    Join Date
    Mar 2008
    Posts
    25
    Got it. Instead of this:

    ./df.sh

    I had to run this:

    . ./df.sh

Posting Permissions

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