LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (https://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   "exec env -i" doesn't seem to work. What am I doing wrong? (https://www.linuxquestions.org/questions/linux-from-scratch-13/exec-env-i-doesnt-seem-to-work-what-am-i-doing-wrong-860426/)

spoovy 02-03-2011 04:21 AM

"exec env -i" doesn't seem to work. What am I doing wrong?
 
Section 4.4 of LFS 6.7 includes the following text -

Code:

Set up a good working environment by creating two new startup files for the bash shell. While logged in as user lfs,
issue the following command to create a new .bash_profile:

       
Code:

       
cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF


When logged on as user lfs, the initial shell is usually a login shell which reads the /etc/profile of the
host (probably containing some settings and environment variables) and then .bash_profile. The exec env
-i.../bin/bash command in the .bash_profile file replaces the running shell with a new one with a completely
empty environment, except for the HOME, TERM, and PS1 variables. This ensures that no unwanted and potentially
hazardous environment variables from the host system leak into the build environment. The technique used here
achieves the goal of ensuring a clean environment.


The problem is that after creating this file and starting a new logon shell as user lfs, and use "set" to list variables, I find that I still have all the host system variables set. The empty environment referred to doesn't happen.

It seems like the "exec env -i" command just isn't working.

Anyone got any ideas? The host is Debian Squeeze.

Thanks

spoov

druuna 02-03-2011 05:23 AM

Hi,

Which variables are you talking about?

After becoming user lfs I see 40 defined variables, if I remove .bash_profile I see 54 (.bashrc is present). Try removing .bash_profile, log in again and check the difference in the output of the set command (do remember to create .bash_profile again after testing).

If the problem still exists:
Quote:

after creating this file and starting a new logon shell as user lfs
Are you using su lfs or su - lfs? It should be the second one.

Hope this helps.

spoovy 02-03-2011 06:32 AM

Thanks I think i've (kindof) figured it - it's something to do with "set" command. If I list variable with "env" then I get the results I would expect. Using "set" gives very strange results though. See below ('m starting from a newly opened shell (terminator, opened via openbox menu).

Code:

[spoovy@poppy-debian:~] $ set > file2
[spoovy@poppy-debian:~] $ wc -l file2
57 file2
[spoovy@poppy-debian:~] $ su - spoovy
Password:
[spoovy@poppy-debian:~] $ set > file3
[spoovy@poppy-debian:~] $ wc -l file3
8736 file3
[spoovy@poppy-debian:~] $

Again starting with a new shell -

Code:


[spoovy@poppy-debian:~] $ su - spoovy
Password:
[spoovy@poppy-debian:~] $ set > file
[spoovy@poppy-debian:~] $ wc -l file
8733 file
[spoovy@poppy-debian:~] $ su - root
Password:
root@poppy-debian:~ # set > file
root@poppy-debian:~ # wc -l file
8733 file
root@poppy-debian:~ # su - lfs
[lfs@poppy-debian:~] $ set > file
[lfs@poppy-debian:~] $ wc -l file
40 file


druuna 02-03-2011 07:46 AM

Hi,

env shows only the environment, set shows all variables. As stated before I also come up with 40 if I run set | wc -l.

Guess you're problem is solved (if it is mark it as such: First post -> Thread Tools).

spoovy 02-03-2011 11:09 AM

Hmm. As well as variables, set also returns a huge barrage of code after the variables when run from a login shell (I wont post it here as there's 8,700+ lines). I don't know if this is the proper behaviour?

I'm assuming that my x-launched terminal is not a login shell (though I thought these were login shells - you learn something every day).

druuna 02-03-2011 11:36 AM

Hi,

No need to worry, at all.

The set command shows everything that is set during the login process and there are big differences in the amount of lines when counted. To give you an example: My LFS box has 109 lines total and my debian squeeze box has 8823 lines total when running set | wc -l.......

The outcome of the env command should be a lot closer together (LFS 42, Debian 38 on my boxes).

Hope this helps.

spoovy 02-03-2011 12:47 PM

Thanks, yeah 40 and 57 respectively for me when using env. Cheers druuna, marking as solved.

druuna 02-03-2011 01:19 PM

You're welcome :)


All times are GMT -5. The time now is 05:01 PM.