LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-30-2003, 04:48 PM   #1
mikeshn
Member
 
Registered: Feb 2002
Distribution: Fedora Core 2
Posts: 587

Rep: Reputation: 30
bashrc vs. bash_profile


These two files looks pretty similar. What is the purpose of these files ?

Thanks
 
Old 08-30-2003, 05:01 PM   #2
DrOzz
Senior Member
 
Registered: May 2003
Location: Sydney, Nova Scotia, Canada
Distribution: slackware
Posts: 4,185

Rep: Reputation: 58
things like:
PATHS
custom PS1 strings
aliases
....etc,are stored in these files...
 
Old 08-30-2003, 05:08 PM   #3
Skyline
Senior Member
 
Registered: Jun 2003
Distribution: Debian/other
Posts: 2,104

Rep: Reputation: 45
One important distinction is that bash_profile is read when you loggin whereas bashrc is read each time you open a bash shell after youve logged in.
 
Old 08-30-2003, 05:11 PM   #4
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 32
When you start a login shell, bash consults the following files in the specified order:
1. /etc/profile
2. ~/.bash.profile
3. ~/.bash_login
4. ~/.profile
When you start a nonlogin shell, bash consults only one startup file, ~/bash.rc.
 
Old 09-24-2003, 08:45 AM   #5
mikeshn
Member
 
Registered: Feb 2002
Distribution: Fedora Core 2
Posts: 587

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by SaTaN
When you start a login shell, bash consults the following files in the specified order:
1. /etc/profile
2. ~/.bash.profile
3. ~/.bash_login
4. ~/.profile
When you start a nonlogin shell, bash consults only one startup file, ~/bash.rc.
What do you mean by "nonlogin shell"? When OS starts?
 
Old 09-24-2003, 05:43 PM   #6
Skyline
Senior Member
 
Registered: Jun 2003
Distribution: Debian/other
Posts: 2,104

Rep: Reputation: 45
Just think of a non-login shell as when you open a new instance of bash up after youve logged in - each time you do this the ~/.bashrc file is read - this file is good for putting Aliases in amongst other things.
 
Old 09-27-2003, 08:27 PM   #7
bleedingpegasus
LQ Newbie
 
Registered: Sep 2003
Location: where rainbow begins
Distribution: RH Psyche
Posts: 7

Rep: Reputation: 0
is there any command that can be use for restarting the .bash_profile, so don;t have to restart the whole pc?
i mean, like in windows, you can restart the 'explorer' only if you made changes in registry....

TIA.
 
Old 09-28-2003, 12:43 AM   #8
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 32
On the command line:-
. .bash_profile
 
Old 10-04-2003, 09:20 PM   #9
mikeshn
Member
 
Registered: Feb 2002
Distribution: Fedora Core 2
Posts: 587

Original Poster
Rep: Reputation: 30
What .(dot) before .bash_profile does?
 
Old 02-10-2008, 02:46 PM   #10
vamped
LQ Newbie
 
Registered: Oct 2006
Posts: 13

Rep: Reputation: 0
Quote:
Originally Posted by mikeshn View Post
What .(dot) before .bash_profile does?
It's been a long time, but for completeness:

If you run it like:
$ .bash_profile
it creates a new process to run the file. Any aliases created will be valid only for that process. When the file is finished running, that process ends, and the new aliases expire.
If you run it like:
$ . .bash_profile
it runs it in the current process. When the file is finished executing, the new aliases are still valid.

See $man . OR $man source
 
Old 01-26-2012, 03:04 AM   #11
pavlosVos
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
.bash_profile vs .bashrc by Josh Staiger

.bash_profile vs .bashrc
by Josh Staiger

WHEN working with Linux, Unix, and Mac OS X, I always forget which bash config file to edit when I want to set my PATH and other environmental variables for my shell. Should you edit .bash_profile or .bashrc in your home directory?
You can put configurations in either file, and you can create either if it doesn’t exist. But why two different files? What is the difference?
According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
What is a login or non-login shell?

When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.
But, if you’ve already logged into your machine and open a new terminal window (xterm) inside Gnome or KDE, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.
Why two different files?

Say, you’d like to print some lengthy diagnostic information about your machine each time you login (load average, memory usage, current users, etc). You only want to see it on login, so you only want to place this in your .bash_profile. If you put it in your .bashrc, you’d see it every time you open a new terminal window.
Mac OS X — an exception

An exception to the terminal window guidelines is Mac OS X’s Terminal.app, which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. Other GUI terminal emulators may do the same, but most tend not to........
for more...

search for title and Josh Staiger

PS: all credit goes to Josh Staiger
I just connect the dots

yours

Pavlos
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
bashrc or bash_profile ? ARCIS_house Linux - Newbie 6 07-21-2005 03:09 PM
.bashrc .bash_profile Soulful93 Slackware 4 05-03-2005 04:02 AM
~/.bashrc, ~/.bash_profile Sinope Linux - Newbie 6 08-17-2004 03:40 AM
.bashrc or .bash_profile? statmobile Linux - Newbie 1 02-04-2004 10:08 PM
.bashrc vs .bash_profile xor3 Linux - Newbie 1 08-16-2003 01:52 PM


All times are GMT -5. The time now is 12: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
Open Source Consulting | Domain Registration