Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Linux, .bashrc

Posted on 2012-04-02
5
Medium Priority
?
585 Views
Last Modified: 2012-04-03
What is the purpose of the .bashrc file as oposed to the .profile file
0
Comment
Question by:Los Angeles1
5 Comments
 
LVL 15

Assisted Solution

by:mish33
mish33 earned 400 total points
ID: 37796718
.profile runs when you log in
.bashrc run on every new terminal window
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 400 total points
ID: 37796727
.profile is typically for login shell.  So it is triggered when you logon.
.bash.rc is triggered every time a subshell is spawned.
0
 
LVL 26

Assisted Solution

by:pony10us
pony10us earned 400 total points
ID: 37796733
I think this:  http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html  might give you a good starting point to understanding the difference.

Basically the bash_profile runs like a windows login script (only at login) as opposed to bashrc runs in the background as a process monitoring everything continously.

That is a very basic explanation and is detailed better at the link above.
0
 
LVL 11

Assisted Solution

by:legolasthehansy
legolasthehansy earned 400 total points
ID: 37796745
THe .bashrc file is your start up file when you login. Your aliases can be defined here so that you can run them while you are on shell.
eg. - alias rm='rm -i'

Do a cat ~/.bashrc to see it

The .profile file is for non-bash shells to load environment variables.
0
 
LVL 1

Accepted Solution

by:
Faher earned 400 total points
ID: 37800276
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
...
When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.

As far as I understand, a login shell means a session where you log in to the system and directly end up in Bash, like a remote ssh session or logging in through a non-graphical text terminal. A non-login shell is then the type of shells you open after logging in: typically in a graphical session when you open a new terminal window.

How I think things are supposed to work (for a typical setup):

.profile is for things that are not specifically related to Bash, like environment variables PATH and friends, and should be available anytime. For example, .profile should also be loaded when starting a graphical desktop session.

.bashrc is for the configuring the interactive Bash usage, like Bash aliases, setting your favorite editor, setting the Bash prompt, etc.

As stated in the man page excerpt above, if you would omit .bash_profile, only .profile would be loaded.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month6 days, 5 hours left to enroll

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question