Difference Between .bashrc and .bash_profile :

We use .bashrc and .bash_profile frequently to set environment for Oracle.

Here is the difference between both files ,which file is used when .

  • location of .bashrc : /home/username/.bashrc
  • location of .bash_profile : /home/oracle/.bash_profile

.bashrc : This file is executed for non-login shells .
.bash_profile : This file is executed for login shells.

Now , what is login shells and non-login shells ,

When you connect to a machine [linux or unix] with your user name and password , either physically or remotely with ssh , that is considered as login shells and .bash_profile is executed to configure your shell before the initial command prompt.

And When you’re already logged into your machine and open a new terminal window or new tab then that is considered as non-login shells and .bashrc file is executed to configure your shell.

As Suggestion given by Santosh

.bash_profile for self logins . login with user name and password.
.bashrc for (r)emote (c)onnections..the connections that we do with ssh.. sometime we will login one server and do some operations then we do ssh ..remote connection and perform some operations in the remote server.. .bashrc variables will be loaded as environment variables can be invoked inside script during ssh..remote connections.

For example. you are in server A. And u have one more server called Server B.
U have logged into server A with its user name and password. While u r logging in server A, the server will export all the variables of .bash_profile and u can echo those variables later. After logged in Server A, then u can connect to sever B via SSH directly or through shell script, while u r connecing to Server B, .bashrc variables will be loaded in Server B session and u can able to use and echo those variables.

Thank you for giving your valuable time to read the above information.

If you want to be updated with all our articles send us the Invitation or Follow us:

Skant Gupta’s LinkedIn: www.linkedin.com/in/skantali/

Joel Perez’s LinkedIn: Joel Perez’s Profile

Anuradha’s LinkedIn: Anuradha’s Profile

LinkedIn Group: Oracle Cloud DBAAS

Facebook Page: OracleHelp

About The Author

Comments

  1. Tausif Khan

    Dear Team,

    As above article definitions of .bashrc and .bash_profile as below. but here .bashrc definitions should be of .bash_profile and vise versa.
    .bashrc : This file is executed for login shells .
    .bash_profile : This file is executed for non-login shells.

  2. Aqeel Nawaz

    I am bit confused about following.

    .bashrc : This file is executed for login shells .
    .bash_profile : This file is executed for non-login shells.

    Is the following same as above

    Now , what is login shells and non-login shells ,

    When you connect to a machine [linux or unix] with your user name and password , either physically or remotely with ssh , that is considered as login shells and .bash_profile is executed to configure your shell before the initial command prompt.

    Need your clarification.

    ranaaqeel_nawaz@yahoo.com

  3. mdecker

    Hi,

    it is the other way around:

    wrong:

    .bashrc : This file is executed for login shells .
    .bash_profile : This file is executed for non-login shells.

    Regards,
    Martin

  4. Santhosh

    .bash_profile for self logins ..i mean login with user name and password.
    .bashrc for (r)emote (c)onnections..the connections that we do with ssh.. sometime we will login one server and do some operations then we do ssh ..remote connection and perform some operations in the remote server.. .bashrc variables will be loaded as environment variables can be invoked inside script during ssh..remote connections.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.