LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 11-14-2005, 05:13 AM   #1
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 433

Rep: Reputation: 30
Where are environment variables stored?


Simple question huh?
 
Old 11-14-2005, 05:44 AM   #2
lacerto
Member
 
Registered: Oct 2003
Location: South London
Distribution: Gentoo.
Posts: 297

Rep: Reputation: 30
In my distro, they are in /etc/profile or /etc/profile.env
 
Old 11-14-2005, 05:53 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
This is not the place where they are stored but where the global environment variables are defined.

Environment variables are stored in every process memory, and accessible through the getenv and putenv libc functions.
 
Old 11-14-2005, 06:01 AM   #4
lacerto
Member
 
Registered: Oct 2003
Location: South London
Distribution: Gentoo.
Posts: 297

Rep: Reputation: 30
Good point - I wasn't clear on what was being asked
 
Old 11-15-2005, 01:54 AM   #5
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 433

Original Poster
Rep: Reputation: 30
Thx for the help. The reason I asked is because Linux from Scratch uses a script which basically clears out all environment varialbes except the one you need.

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:
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 new instance of the shell is a non-login shell, which does not
read the /etc/profile or .bash_profile files, but rather reads the
.bashrc file instead. Create the .bashrc file now:
cat > ~/.bashrc << "EOF"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL PATH
EOF

Lets say the HOME variable was set in /etc/profile. What does assigning the variable to itself do? What does this change? After I exit the shell how does PATH get reset to the orginal value. I guess that's what I really want to know.
 
Old 11-15-2005, 02:35 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
As I wrote, environment variables are stored in each process memory, they are not shared, they are only inherited when exported.
So there is no need to "restore" the PATH to its original value when you exit the shell, as the PATH has stayed as it was in the parent shell.
 
Old 11-15-2005, 06:41 PM   #7
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 433

Original Poster
Rep: Reputation: 30
Thx, I understand what you mean now. When linux first starts up, the login bash shell is given the environment variables from the kernel. These starting values are stored in the profile file. Essentially, export is like the public keyword in C++. All other varaibles are private.

A few more quick questions though. When does the .bash_profile file get read? Is this naturally read?
 
Old 11-15-2005, 07:00 PM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Quote:
When linux first starts up, the login bash shell is given the environment variables from the kernel.
Not directly, the shell is given its environment variable by its parent process, which depend on how you launched that shell (sshd, inetd, init, a terminal emulator, ...)
Quote:
These starting values are stored in the profile file.
No, the starting values are inherited, then, if the shell is a login shell, it reads the profile file(s) and add the variables found there to its environment. If some of these variables are exported, that means that any process launched later by the shell will inherit them.
Quote:
Essentially, export is like the public keyword in C++. All other varaibles are private.
yes.
Quote:
A few more quick questions though. When does the .bash_profile file get read? Is this naturally read?
.bash_profile is read by bash when it starts as a login shell.
 
Old 11-15-2005, 08:54 PM   #9
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 433

Original Poster
Rep: Reputation: 30
Jilagre, you are awsome. All my questions have been answered.
 
  


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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
where are the environment variables stored? ojav Linux - Newbie 3 05-31-2005 04:00 PM
where does static and global variables stored raviksp General 0 04-28-2005 12:23 AM
commands stored into variables? benne Programming 2 11-15-2004 07:20 PM
Where are variables permaninently stored? tearinox Linux - General 4 06-05-2004 10:42 AM
Where are the environmental variables (eg. $DISPLAY) stored? davidas Linux - Newbie 2 04-08-2004 01:33 AM


All times are GMT -5. The time now is 09:11 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration