?
Solved

Linux, .bashrc

Posted on 2012-04-02
5
Medium Priority
?
580 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 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