Solved

Linux, .bashrc

Posted on 2012-04-02
5
571 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 100 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 100 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 100 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 100 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

863 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

Need Help in Real-Time?

Connect with top rated Experts

30 Experts available now in Live!

Get 1:1 Help Now