Solved

Linux, .bashrc

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
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…
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.

726 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