![](https://seccdn.libravatar.org/avatar/9e9cd0ac4b9e1e8633e84a8070485076.jpg?s=120&d=mm&r=g)
On Wednesday 05 January 2005 07:20, contiemilio@virgilio.it wrote:
Alle 13:36, martedì 4 gennaio 2005, Koenraad Lelong ha scritto:
Hi, I have a script to set a number of environment variables, including the PATH. It seems not to work. After the script terminates, the variables and the new path are gone or in their original state. Is this normal behaviour, or is there a misconfigured setting ? I modified the script to echo the path, and that's fine, but when I echo it after the script has run, it's in it's original state. Sugestions and pointers to reading material are welcome. The script : #!/bin/bash # dev-arm-qpe.sh script # location : /usr/bin #
if [ -z ${ORG_PATH} ] then ORG_PATH=${PATH} export ORG_PATH fi
if [ -z ${ORG_LD_LIBRARY_PATH} ] then ORG_LD_LIBRARY_PATH=${LD_LIBRARY_PATH} export ORG_LD_LIBRARY_PATH fi
CROSSCOMPILE=/opt/Embedix/tools:/usr/local/x86/2.95.3/bin:/opt/Embedix/ tool s QPEDIR=/opt/Qtopia/sharp QTDIR=/opt/Qtopia/sharp PATH=$QTDIR/bin:$QPEDIR/bin:$CROSSCOMPILE/bin:${ORG_PATH} TMAKEPATH=/opt/Qtopia/tmake/lib/qws/linux-sharp-g++/
### Commented out next line. No need to set LD_LIBRARY_PATH ! ### LD_LIBRARY_PATH=$QTDIR/lib:${ORG_LD_LIBRARY_PATH}
export QPEDIR QTDIR PATH LD_LIBRARY_PATH TMAKEPATH PS1 echo "Altered environment for Sharp Zaurus Development ARM" <snip> If you need such environment variables you must set them in /etc/profile or, better, in .bashrc in your home directory. You are correct, but Koenraad does not understand one of the basic concepts of Unix/Linux.
Setting of environment variables is performed at the current process and
inherited by the child processes. It is not global. If you want to use a
script to set environment variables, you may source that script.
example:
$ source dev-arm-qpe.sh
This will cause the script to be executed in your current process.
This is a major conceptual difference between Windows where the setting of
an environment variable is global and will affect other running processes
where in Linux it does not. When you run a script or a program, the shell
(bash in this case) creates a child process in which the script runs. Thus,
anything nasty that the child process may do, it will not affect the
parent's environment.
--
Jerry Feldman