DaViD_BRaNDoN Posted October 15, 2007 Share Posted October 15, 2007 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 More sharing options...
markwolfe Veteran Posted October 15, 2007 Veteran Share Posted October 15, 2007 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 More sharing options...
DaViD_BRaNDoN Posted October 15, 2007 Author Share Posted October 15, 2007 Ahhh... I see the problem now. Thanks so much for the tip! Gonna try out the "source" stuff later. Link to comment Share on other sites More sharing options...
Mike Posted October 15, 2007 Share Posted October 15, 2007 all the source stuff is instead of running the script (./path.sh) source it (. ./path.sh) Link to comment Share on other sites More sharing options...
DaViD_BRaNDoN Posted October 15, 2007 Author Share Posted October 15, 2007 Just tried it on Knoppix LiveCD and yes, the "source" trick really works! Thanks again Link to comment Share on other sites More sharing options...
Recommended Posts