LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-14-2014, 01:16 PM   #1
Avan
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Rep: Reputation: Disabled
.bashrc and bash_profile files


Hello,

Can some one tell me what is the job of .bashrc and .bash_profile files?

Regards,
Avan
 
Old 10-14-2014, 01:29 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,473

Rep: Reputation: 420Reputation: 420Reputation: 420Reputation: 420Reputation: 420
.bashrc initializes commands for bash interactive shell
.bash_profile initializes commands for bash login shell
 
3 members found this post helpful.
Old 10-15-2014, 05:06 AM   #3
josephj
Member
 
Registered: Nov 2007
Location: Northeastern USA
Distribution: kubuntu
Posts: 146

Rep: Reputation: 79
Elaborating

While @keefaz gave the correct answer, it was a bit terse.

When you first log in to a system, a special flag is set on bash to tell it it's a login shell. .profile is run only for login shells - which is usually only once per session. So, it's used for setting up custom things in your "environment" that usually hold true for your whole session. You might put something there which launches a user-level helper program or utility that you always want to be there. It typically also runs .bashrc near the start of its processing.

I have a little program that generates a pop-up to notify me whenever I go offline. I start it from .profile and it runs in the background waiting for my connection to break - like a very simple daemon.

When you start any interactive shell - one that is usually connected to your keyboard and screen, .bashrc is run. If you open three terminal windows in a terminal program like gnome-terminal or kate, .bashrc is run in each of them.

It's good for things like setting how your shell history behaves, setting your shell prompt strings, setting environment variables, defining aliases, and custom functions.

I have a function to switch me to my user's bin directory defined in .bashrc. Since it's a function and not a separate script, it runs at the shell level where it was invoked, so the effect of the cd command sticks and is not lost like it would be if it were run in its own script which would execute in a subshell.

bin() {
cd $HOME/bin
echo -en "\t\t"
pwd
}

and one for a command line calculator.

## Command line calculator
calc () {
bc -l <<< "$@"
}
 
2 members found this post helpful.
Old 10-15-2014, 06:26 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,905

Rep: Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921
the best answer is the man page of bash, see invocation (and different flags like -l, --noprofile ...)
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] /etc/bashrc ,dircolors and /root/.bash_profile ,/.bashrc not exist in LFS-7.5(sec9.3) jaassi Linux From Scratch 2 09-20-2014 06:04 PM
How to edit .bash_profile and .bashrc files? LinuxInfo Programming 9 07-21-2012 10:19 AM
.bashrc / .bash_profile /etc/profile /etc/bashrc deadeyes Red Hat 2 02-13-2010 12:22 PM
~/.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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:23 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration