LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   .bashrc and bash_profile files (https://www.linuxquestions.org/questions/linux-newbie-8/bashrc-and-bash_profile-files-4175522111/)

Avan 10-14-2014 12:16 PM

.bashrc and bash_profile files
 
Hello,

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

Regards,
Avan

keefaz 10-14-2014 12:29 PM

.bashrc initializes commands for bash interactive shell
.bash_profile initializes commands for bash login shell

josephj 10-15-2014 04:06 AM

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 <<< "$@"
}

pan64 10-15-2014 05:26 AM

the best answer is the man page of bash, see invocation (and different flags like -l, --noprofile ...)


All times are GMT -5. The time now is 06:45 AM.