Sections

  • About Author
  • Contact
  • Debian Hosting
  • Popular Posts
  • Privacy Policy
  • Sitemap

Debian Admin

Debian/Ubuntu Linux System Administration Tutorials,Howtos,Tips

Categories

  • Backup
  • Database
  • Free-Tools
  • General
  • Monitoring
  • Network
  • Other Linux
  • Package-Mgmt
  • Paloalto Firewalls
  • Security
  • Webserver

Difference between .bash_profile and .bashrc Files

Posted on April 16, 2007 by ruchi 4 Comments

One of the things you always have trouble remembering when working with linux is what is the correct “.profile” to edit when you want to automatically set environmental variables.

According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

when you login when using a console, either physically at the machine or using ssh, .bash_profile is executed.

However, if you launch a terminal within a windowing system such as GNOME,KDE, launch the Emacs *shell* mode, or execute /bin/bash from within another terminal then .bashrc is executed.

Most people edit the files so one calls the other anyway.

To do this you need to open .bash_profile and uncomment the following lines (under the comment # include .bashrc if it exists):

if [ -f ~/.bashrc ];
then
source ~/.bashrc
fi

Now when we login to our machine from a console,.bashrc will get called.

Related content:

  1. How to Add Date And Time To Your Bash History file
  2. Howto Create your own aliases in Debian
  3. Users and Groups Administration in Linux
  4. Shutting down Debian linux machine
  5. colordiff — a tool to colorize diff output

Categories: General

Tags: Difference-between-.bash_profile-and-.bashrc-files, user-profile-files

4 thoughts on “Difference between .bash_profile and .bashrc Files”

  1. anon on April 17, 2007 at 5:54 pm said:

    Is there a system wide .bashrc like file? For interactive logons /etc/profile is sourced, but for non interactive I would really like to have a system wide file for all users without having to resort to making a .bashrc file on . /etc/profile.

    Thanks

  2. beijing on April 20, 2007 at 8:02 am said:

    yes there is /etc/bash.bashrc (in my Edgy at least).

  3. Scott on February 8, 2010 at 7:29 pm said:

    Well I want both .bashrc and .bash_profile to be called whether from emacs shell or login. Having profile call rc works fine for login; but if emacs wants rc to call profile, you’d be creating an incredible infinite loop, right?

    So put something like this in rc maybe? (or in each file?)

    [ -z “RC_BEEN_THERE” ] || return
    export RC_BEEN_THERE=”TRUE”
    # etc….
    source ~/.bash_profile

    Or am I missing something obvious?

    PS – it seems that on my lenny system, the login calls .bashrc for a *root* login, but not a user. What’s up with that?

  4. Tom on July 23, 2013 at 5:04 pm said:

    Why not simply create a symbolic link? I put everything I need in .bashrc and create a symbolic link called .bash_profile pointing to .bashrc

Leave a comment

Your email address will not be published. Required fields are marked *

« MySQL Database Server Installation and Configuration in Debian
GnuCash financial-accounting software in Debian »

Sponsored Link

    Cheap Web Hosting

Categories

  • Backup
  • Database
  • Free-Tools
  • General
  • Monitoring
  • Network
  • Other Linux
  • Package-Mgmt
  • Paloalto Firewalls
  • Security
  • Webserver

Sponsored Link

Archives

Sponsored Link

Favourite Sites

Ubuntu Geek
  • About Author
  • Contact
  • Debian Hosting
  • Popular Posts
  • Privacy Policy
  • Sitemap