On Mon, Aug 11, 2008 at 8:17 PM, Bob Proulx <bob@xxxxxxxxxx> wrote: > Erez Zilber wrote: >> before running rpmbuild, I run the following commands: >> [erez.zilber@klab002:~/work/]$ sudo bash -c 'export MY_ENV_VAR=some_val' > > This has no effect because in Unix and Unix-like systems every process > starts with a copy of the current environment and at the termination > of the program the copied environment for that program is reclaimed by > the system. > > In the above you are spawning a new environment for the 'sudo' > command. That is spawning a new environment for the 'bash' command. > In the bash process the environment variable is being set. That is > the entirety of the bash script and the bash process terminates at > that point. The system frees and reclaims all of the process memory > associated with the bash process including all environment memory > space. The sudo command has been waiting for the bash process to > exit. It observes the program exit code and then the sudo process > itself exits. When the sudo process exits the process memory > including all environment memory is freed and reclaimed by the > system. > >> [erez.zilber@klab002:~/work/]$ sudo echo $MY_ENV_VAR >> some_val > > This is because you have already set MY_ENV_VAR in the parent > environment. The $MY_ENV_VAR is expanded by the shell before it > invokes the sudo. The sudo then invokes echo with the some_val > argument. Try this for comparison: > > $ echo debug: sudo echo $MY_ENV_VAR > debug: sudo echo some_val > > The $MY_ENV_VAR will already have been expanded by the original > invoking command line shell. > >> In the spec file, I print this env var: >> >> %build >> echo "MY_ENV_VAR = $MY_ENV_VAR" >> but when I run rpmbuild --rebuild >> /usr/src/redhat/SRPMS/mypackage-0-0.1.src.rpm, I get: >> >> + LANG=C >> + export LANG >> + unset DISPLAY >> + echo 'MY_ENV_VAR = ' >> MY_ENV_VAR = >> >> I guess that it opens another shell in which the env var is not >> defined. How can I solve that (without adding the env var to .bashrc >> which is not a possible solution for me). > > Export the variable in the parent environment. It will then be > inhereted by the child environments. > > Either for the specific command: > > $ MY_ENV_VAR=some_val rpmbuild --rebuild mypackage-0-0.1.src.rpm > > Or: > > $ export MY_ENV_VAR=some_val > $ rpmbuild --rebuild mypackage-0-0.1.src.rpm > > Note that it is dangerous to use sudo to build rpm packages. This > causes the build to run as root. You don't want to do that. The > wisdom of thet 'net is that this should be avoided. Package building > should be done as a non-privileged user. > > Bob > Thanks! That was very helpful. Erez _______________________________________________ Rpm-list mailing list Rpm-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/rpm-list