ubuntu: profile.d and .bash_profile missing

Posted on

Problem :

I have done some reading up on Linux startup, etc and I noticed that in my home directory it is not present a folder profile.d:

/home/user/profile.d/ # Doesn't exists

and nor a file .bash_profile:

/home/user/.bash_profile # Doesn't exists

is there a reason for this?

Ubuntu 15.04, gnome

Solution :

Short answer: it is ok so.

There are many initialization user files because an user can decide to log in a computer account in many different way, from console, with an interactive or a non interactive shell, with different kind of shells. It is not a prerogative of all the users, but with the need to keep a backward compatibility it finished to complicate a little the things. 🙂

  • A directory profile.d should not to be under your home directory:
    /etc/profile.d contains scripts with application-specific startup files, which are also executed at startup time by the shell.
    It is a directory valid for all the users, for this it is created under the /etc/ path and not under each single user home directory.

  • The file ~/.bash_profile is one of the personal initialization files and when it exists is stored in each user home. But it is not needed that it exists. It should contain the bash-specific commands to be run when starting a login shell (~/.profile can be read from different shells too, that usually understand a syntax different from the bash one).

Reading more from the INVOCATION section of man bash

When bash is invoked as an interactive login shell (…) it first reads and executes commands from the file /etc/profile, if that file exists.
After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and
executes commands from the first one that exists and is readable.

So if you have a ~/.bash_profile file it will not be read the ~/.profile, if not called (or sourced) in one of the other files.

Note that

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.

From some version of Ubuntu 12 (and for sure from 13.10) in the .profile is sourced the ~/.bashrc.

This can cause unexpected behavior when running login shells (such as when ssh into the machine for example) where the user would not expect to have ~/.bashrc sourced.