[Help] Linux Shell Script


Recommended Posts

I need help in Linux shell scripting. I want to add some environment variables using shell script. Currently, this is what I have in my "Path.sh":

#!/bin/sh
PATH="/media/sda1/Linux/Programs/JavaSDK/bin:/media/sda1/Linux/Programs/MIDP/bin:$PATH"
export PATH
CLASSPATH="/media/sda1/Linux/Programs/JavaSDK/lib:/media/sda1/Linux/Programs/MIDP/lib:$CLASSPATH"
export CLASSPATH
MIDP_HOME="/media/sda1/Linux/Programs/MIDP:$MIDP_HOME"
export MIDP_HOME

It's not working at the moment. FYI, am using Knoppix LiveCD. Adding the environment variables manually in the terminal works though. Anything work in the above shell script?

Link to comment
Share on other sites

From a little bit of googling, it seems that a child process is given a copy of the environment of the parent. Meaning that when you spawn the script, and it makes changes, they only exist for the scope of that script. Your real user environment still uses the original environment variables, and when the script terminates, the modified environment that was created for it will no longer exist.

It seems that you can use "source" to have your current shell to run the commands, instead of spawning a child that will be unable to change your system's environment. (reference)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.