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/tools 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" -- Met vriendelijke groeten, Koenraad Lelong R&D Manager ACE electronics n.v.
On Tuesday 04 January 2005 14:36, Koenraad Lelong wrote:
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 ?
That is normal behaviour. In order to get the new settings one must use the '.' or source command viz : . <your script> or source <your script> Make sure that you do not have an exit command in <your script>. Paul -- Paul Hewlett (Linux #359543) Email:`echo az.oc.evitcaten@ttelweh | rev` Tel: +27 21 852 8812 Cel : +27 72 719 2725 FAX: +27 866720563 --
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" -- Met vriendelijke groeten, Koenraad Lelong R&D Manager ACE electronics n.v.
If you need such environment variables you must set them in /etc/profile or, better, in .bashrc in your home directory. Bye emilio
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
Jerry Feldman wrote:
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
...
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.
Thanks all of you. I knew (more or less) that I could make 'permanent' changes to the environment with .bashrc. But that's a problem. The development environment is such that you can compile for arm, and for i386, switching using two scripts, of which the posted one is to compile for arm. So using .bashrc is not practical. I'll use the f^Hsource ;-). P.S. Paul Hewlett mentions a ., is this identical to source ? How do you use this if the script is in your local directory ? Anyway, I have to read 'man source'. -- Met vriendelijke groeten, Koenraad Lelong R&D Manager ACE electronics n.v.
P.S. Paul Hewlett mentions a ., is this identical to source ? How do you use this if the script is in your local directory ? Anyway, I have to read 'man source'. works fine using the dot (.) or source.
On Wednesday 05 January 2005 11:33, Koenraad Lelong wrote:
source <filename>
Some commercial compilers come with a script that should be souced before
running the compiler. Sourcing will affect the current shell environment.
--
Jerry Feldman
participants (4)
-
contiemilio@virgilio.it
-
Jerry Feldman
-
Koenraad Lelong
-
Paul Hewlett