Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I want to run a shell script (define some environment variables) at the start of every new shell (globally, not for several users).

So I placed my script into the directory /etc/profile.d/, but that works only for login shells. Is there a better place for my script?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

For interactive login shells, as you've found, you can put commands in scripts located inside:


You can also accomplish that, in a somewhat less desirable way, by editing the global configuration file:


For bash (which is the default interactive shell), there is a corresponding file where you can put commands to be run by all interactive non-login shells:


Just as /etc/profile.d and /etc/profile correspond to ~/.profile, /etc/bash.bashrc corresponds to ~/.bashrc.

This does not apply to non-interactive shells. But it's rather unlikely that you have commands you want run by non-interactive shells. (Then they would run every time any script was run.)

share|improve this answer

Have a look at

share|improve this answer
Could you expand upon this a bit, perhaps adding what that file is, when it is run, and how it's limited (to bash only)? – John S Gruber Aug 12 '12 at 20:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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