LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-07-2005, 11:49 AM   #1
carbono
LQ Newbie
 
Registered: May 2004
Location: Quebec City, Canada
Distribution: RH9, Fedora Core 1
Posts: 10

Rep: Reputation: 0
Unhappy /etc/profile VERSUS /home/.bash_profile


Hi everybody,

I use Debian and I added two environment variables to my .bash_profile file (NEW_ENV_VAR=/pathToEnvVariable; export NEW_ENV_VAR. I also added a directory to the $PATH (PATH=%PATH:/NewDirToPATH.

The problem is that I rebooted and when I start a terminal (bash) and issue the "env" command, my new $PATH and env. variables aren't there, although they are in my .bash_profile. Why? And what's the difference between .bash_profile and /etc/profile? Should I put my commands (mentionned above) in /etc/profile instead of .bash_profile?

Thanks a lot

Gui
 
Old 10-07-2005, 11:52 AM   #2
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Posts: 262

Rep: Reputation: 30
Try putting them in ~/.bashrc instead.

I might have this the wrong way round, but .bash_profile invokes .bashrc, (or should do) - only one is called (.bashrc I think) at the CLI, whereas .bash_profile is called in the GUI, so it still calls .bashrc.

as far as I know, etc/profile is for ALL users.

What exactly does your .bash_profile look like, or at least the lines you have added?

Please post the lines below.
 
Old 10-07-2005, 11:57 AM   #3
carbono
LQ Newbie
 
Registered: May 2004
Location: Quebec City, Canada
Distribution: RH9, Fedora Core 1
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Please post the lines below.

# ~/.bash_profile: executed by bash(1) for login shells.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/login.defs
#umask 022

# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# the rest of this file is commented out.

# set PATH so it includes user's private bin if it exists
#if [ -d ~/bin ] ; then
# PATH=~/bin:"${PATH}"
#fi

# do the same with MANPATH
#if [ -d ~/man ]; then
# MANPATH=~/man${MANPATH:-:}
# export MANPATH
#fi

HDFLOOKMAPS=/usr/local/Maps;
export HDFLOOKMAPS;

HDFLOOKTMP=/usr/tmp;
export HDFLOOKTMP;

PATH=$PATH:/usr/bin/perl;
 
Old 10-07-2005, 12:21 PM   #4
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Posts: 262

Rep: Reputation: 30
I might be wrong in this, but you are exporting your variables to your $PATH, and then you are redefining your $PATH as purely /usr/bin/perl, overwriting all of your previous work.

Try defining your own variables AFTER the "PATH=$PATH:/usr/bin/perl;"

Or, instead of using "export", learn from a point earlier in the script which is commented out:

Code:
# set PATH so it includes user's private bin if it exists
#if [ -d ~/bin ] ; then
# PATH=~/bin:"${PATH}"
#fi
So, 3rd line deals with the path and basically adds ~/bin to your PATH (previous line checks if it exists). Instead of using export, try the following:

Code:
HDFLOOKMAPS=/usr/local/Maps;
PATH=HDFLOOKMAPS:"${PATH}";

HDFLOOKTMP=/usr/tmp;
PATH=HDFLOOKTMP:"${PATH}";
I think that's right anyway, although I haven't tried it, so PLEASE MAKE A BACKUP FIRST.

Also, why do you only have "/usr/bin/perl" as your path? Do you not use anything else but perl? Logically, you should have /bin;/sbin;/usr/bin;$HOME/bin; etc?

Last edited by morrolan; 10-07-2005 at 12:26 PM.
 
Old 10-07-2005, 02:22 PM   #5
carbono
LQ Newbie
 
Registered: May 2004
Location: Quebec City, Canada
Distribution: RH9, Fedora Core 1
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks morollan, but in fact I think your wrong (or maybe I am?)

PATH=$PATH:/usr/bin/perl;

The command above doesn't override the previous $PATH. Instead, it appends "/usr/bin/perl" to end of the existing $PATH, as

PATH=/usr/bin/perl:$PATH;

would put "/usr/bin/perl" at the beginning of $PATH, followed by the other directories in already in $PATH.


I think environment variables are something different than PATH (maybe I'm wrong here, someone please correct me if I am). That's why I think that creating my 2 env. variables before adding "/usr/bin/perl" to my PATH doesn't make any difference to PATH. They're different things.

Try it for yourself: at the command line, create an env. variable (ENVVAR=/home; export ENVVAR and then try the "env" command. You will see your new ENVVAR and you will also see what's inside PATH (e.g. PATH=/usr/bin:/usr/local/bin:/bin)

So I'm still stuck with my problem: how can I permanently create 2 env. variables and also, how can I change my PATH permanently?
 
Old 10-10-2005, 02:41 PM   #6
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Posts: 262

Rep: Reputation: 30
Do you need to do it the way you have stated? Or is any way OK as long as it works?

I'm interested in your problem, and I've been thinking about when I should be thinking of my own problems!

I can add the variables to your PATH, but do you need the variables so you can call them later? so alias HDSLOOKMAPS='cd /usr/local/Maps' won't do?

I'll keep working on it.
 
Old 10-10-2005, 05:58 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally posted by carbono
# ~/.bash_profile: executed by bash(1) for login shells.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/login.defs
#umask 022

# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# the rest of this file is commented out.

# set PATH so it includes user's private bin if it exists
#if [ -d ~/bin ] ; then
# PATH=~/bin:"${PATH}"
#fi

# do the same with MANPATH
#if [ -d ~/man ]; then
# MANPATH=~/man${MANPATH:-:}
# export MANPATH
#fi

HDFLOOKMAPS=/usr/local/Maps;
export HDFLOOKMAPS;

HDFLOOKTMP=/usr/tmp;
export HDFLOOKTMP;

PATH=$PATH:/usr/bin/perl;
The thing is that if you're opening an xterm while logged into a
graphical environment the bash in that terminal ISN'T a login-
shell, and ONLY stuff in ~/.bashrc will be pulled.



Cheers,
Tink
 
Old 10-10-2005, 06:42 PM   #8
init100
LQ Newbie
 
Registered: Oct 2005
Location: Europe
Distribution: Fedora Core 4
Posts: 20

Rep: Reputation: 0
PATH=$PATH:/usr/bin/perl;

First, note that the semicolon ( is not necessary at the end of the line above.

Then, I'm curious to why you want to add /usr/bin/perl to your PATH. Usually, PATH is a list of directories and does not include program filenames. Just adding /usr/bin to your PATH should make sure that you can access perl, as well as all the other programs in /usr/bin.

I think environment variables are something different than PATH (maybe I'm wrong here, someone please correct me if I am). That's why I think that creating my 2 env. variables before adding "/usr/bin/perl" to my PATH doesn't make any difference to PATH. They're different things.

I don't understand what you mean. PATH is just one environment variable among many, and it is only special in that your command shell (bash) interprets it as a list of directories to search for program files when you type a command without specifying its absolute path.

So I'm still stuck with my problem: how can I permanently create 2 env. variables and also, how can I change my PATH permanently?

Maybe the answer to that question is the answer to your question about the various profile and rc files. I'll try to explain the difference between those files.

There are four files of interest:
  • /etc/profile
  • /etc/bashrc
  • ~/.bash_profile
  • ~/.bashrc
The first two files are system-wide configuration files for bash. Anything that you put in them will affect all users on the system. The last two are your user configuration files for bash. Any modifications to these files will only affect your user.

The files /etc/profile and ~/.bash_profile are used when bash is started as a login shell. This usually happens when you log into your X Windows session or log in remotely, using e.g. SSH. Otherwise, the /etc/bashrc and ~/.bashrc files are used. In both cases, the system-wide file is read first, and the user-specific file second.

Setting the PATH variable is usually done in the profile files, since you only want to set those one, not every time you open a new X terminal.

I hope this helps!
 
Old 10-11-2005, 09:10 AM   #9
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Posts: 262

Rep: Reputation: 30
I'm kinda getting the drift now - I've been experimenting and had partial success.

I take your point about /usr/bin/perl not being your PATH and actually being appended to it, I didn't read it properly the first time.

in .bashrc it defines your PATH - you can simply add :/usr/local/Maps:/usr/tmp to the end of that, or you can append it just like you said:

Code:
PATH=$PATH:/usr/local/Maps:/usr/tmp
At the end of .bash_profile. You can also define variables, i.e.

Code:
HDSLOOKMAPS=/usr/local/Maps
I think the problem is, you are trying to export the variable and not the variables target into the PATH, which doesn't appear to work. Also, with the ENV variables, I've only had partial success using them, as below:

Code:
cd HDSLOOKMAPS
I get a message stating that it is a directory, but if I do:

cd $HDSLOOKMAPS
it doesn't produce an error, but it leaves me in the current directory and doesn't move me. I assume ENV variables still use the $ sign, as $HOME and $PATH do.

You could also try aliasing instead of variables.

Code:
alias HDSLOOKMAPS='/usr/local/Maps'
but it all depends on the intended use of the variable, which you haven't made clear.

Last edited by morrolan; 10-11-2005 at 09:12 AM.
 
Old 10-11-2005, 10:10 AM   #10
carbono
LQ Newbie
 
Registered: May 2004
Location: Quebec City, Canada
Distribution: RH9, Fedora Core 1
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks all for clarifying the use of environment variables and the differences between the 4 bash configuration files.

1-I'd like to come back to the use of /usr/bin/perl in my PATH. I realize now that this doesn't make much sense since /usr/bin is already in my PATH and perl is a file located inside /usr/bin. I was getting desperate with another problem with perl so I thought that adding /usr/bin/perl to PATH would help. I didn't think much, this is my mistake.

2- About the use of aliases, well, I don't know a thing about'em. Maybe this would be the solution. I need to set these 2 environment variables (HDFLOOKMAPS and HDFLOOKTMP) to use a software that needs them. If they don't exist, the software pops a window telling me that I need to create these variables.

The reason why these variables are not created every time I log in, I think, is because when I turned on my computer, I log in via some kind of Debian login manager into the Gnome Desktop Environment and maybe this is why the content of ~/.bash_profile isn't executed when, inside Gnome, I open a terminal???

Could this be the problem? And what is the solution to it?

Thanks again all.
 
Old 10-11-2005, 10:41 AM   #11
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Posts: 262

Rep: Reputation: 30
If you create the variables in .bashrc, they will be created whatever you do, because .bash_profile calls .bashrc anyway.

You want to do:

Code:
alias HDFLOOKMAPS='/usr/local/Maps'
alias HDFLOOKTMP='/usr/tmp'
Does the program need to run as root? If so, it won't use your users aliases or variables, althought I think there is a way to preserve them with su or sudo. (can someone clear this up for me please?)

Once saved, press CTRL + ALT +F2 and login. Once logged in, type:

Code:
user@linuxbox ~$ echo $HDFLOOKMAPS
/usr/local/Maps
user@linuxbox ~$
That will check that the variable exists.
 
Old 10-11-2005, 01:23 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
aliases aren't environment variables, aliases allow you to
create synonyms to command sequences without having
to put them in bash-script. What you really wanted is an
Code:
export HDFLOOKMAPS='/usr/local/Maps'
export HDFLOOKTMP='/usr/tmp'
or, in case all you'll ever do with those values
is to cd into the directories
Code:
alias HDFLOOKMAPS='cd /usr/local/Maps'
alias HDFLOOKTMP='cd /usr/tmp'

Cheers,
Tink
 
Old 10-12-2005, 10:23 AM   #13
carbono
LQ Newbie
 
Registered: May 2004
Location: Quebec City, Canada
Distribution: RH9, Fedora Core 1
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks a lot Folks!

I added

Code:
export HDFLOOKMAPS='/usr/local/Maps'
Code:
export HDFLOOKTMP='/usr/tmp'
to .bashrc and I verified that they were set with

Code:
echo $HDFLOOKMAPS
Code:
echo $HDFLOOKTMP
Thanks agin!

Gui
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
KDE 1.4 HOME profile peterman9898 Linux - Software 0 11-19-2005 01:12 PM
Corporate versus Home editions??? unixfreak Linux - Newbie 2 08-15-2004 05:04 PM
ksh93 not reading $HOME/.profile!!! maxw_cc Red Hat 1 03-21-2004 11:03 AM
.profile & .bash_profile on $LFS cbates55 Linux - Distributions 1 01-02-2002 03:25 PM
profile, .bash_profile & ???? ChimpFace9000 Linux - General 1 07-05-2001 05:52 PM


All times are GMT -5. The time now is 02:33 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration