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.