LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 02-03-2011, 04:21 AM   #1
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Rep: Reputation: 43
"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

Last edited by spoovy; 02-03-2011 at 04:26 AM.
 
Old 02-03-2011, 05:23 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 02-03-2011, 06:32 AM   #3
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
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
 
Old 02-03-2011, 07:46 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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).
 
Old 02-03-2011, 11:09 AM   #5
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
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).
 
Old 02-03-2011, 11:36 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
1 members found this post helpful.
Old 02-03-2011, 12:47 PM   #7
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
Thanks, yeah 40 and 57 respectively for me when using env. Cheers druuna, marking as solved.
 
Old 02-03-2011, 01:19 PM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 08:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration