Normally, in bash, the answer would be ~/.bashrc or /etc/bash.bashrc. But unfortunately Ubuntu is sourcing these files from ~/.profile and /etc/profile respectively. So, where should I put such commands on Ubuntu?

See also Why is /etc/profile not invoked for non-login shells? if you are not familiar with these files.


If you open your man bash, you can find somewhere at the line 150:

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.

So, you can use with confidence ~/.bashrc (or /etc/bash.bashrc, but I will not advice you to use this system wide file) for your purpose. And yes, in Ubuntu.

  • Sorry, but that is not correct. As I stated in my question, Ubuntu is sourcing .bashrc from .profile. Thus commands in .bashrc are also executed for login shells. – Seb Feb 24 '14 at 23:43
  • @Seb You didn't specified nothing about login shells in your question... Than, if you have a problem because .bashrc is sourced from .profile when you enter in a login shell, just comment or delete the line from .profile where .bashrc is sourced. – Radu Rădeanu Feb 25 '14 at 4:30
  • Excuse me? Read the very heading of my question: "interactive, non-login shells". How much more specific can I make it? Of course I know I can edit .profile and remove the source, but I am administrating a network of 40 machines and want to keep them as close as possible to "normal ubuntu" to minimize surprises later down the track (consider release upgrades etc). So I thought I'd ask whether Ubuntu has a standard place to put commands for interactive, non-login shells. Given the lack of useful answers, it seems not. – Seb Feb 26 '14 at 0:11

It appears there is no standard place for such commands on Ubuntu (without modifying behaviour that may be considered standard on Ubuntu). Here is a work-around that I came up with:

Add this to the beginning of /etc/profile:


Then, in /etc/bash.bashrc or ~/.bashrc test for this variable:

if [ -n "${IS_LOGIN_SHELL-}" ]; then
   # Put your commands here

Hopefully the variable name won't collide with anything else and this doesn't change what other parts of Ubuntu may rely on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.