Announcement

Collapse
No announcement yet.

Clearing out environment variables

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Clearing out environment variables

    Hello All,

    I am trying to clear out environment variables in a script. This is in the korn shell.

    At the prompt I can do:
    "unset VARIABLE_NAME"
    and it clears out the value.

    But when I try to do the exact same thing within the shell script it has no effect.

    What am I doing wrong?
    Thanks,

    Craigbert
    ----------------------------------------------------
    Kubuntu 13.04
    8GB RAM & Intel Core i7 1.87GHz
    Registered Linux User 537624

    #2
    It's just not possible from a script. A script is a child process. Child processes cannot modify the environment variables of the parent process. In the script, the variable is unset. However, after the script exits and you are back in the parent process, the environment variable is unchanged.

    An alternative is to "source" the file containing the "unset VARIABLE_NAME". The "source" command runs the commands in the file from the current process -- as though they were typed in at the command prompt.

    Comment


      #3
      Spot on! That was the trick!

      Thanks for the tip and explanation. Very helpful.
      Thanks,

      Craigbert
      ----------------------------------------------------
      Kubuntu 13.04
      8GB RAM & Intel Core i7 1.87GHz
      Registered Linux User 537624

      Comment

      Working...
      X