0

I'm on OS X and according to man bash /etc/profile is the system wide configuration for the bash shell.

For testing purposes I opened this file up :

open_profile(){
    sudo chmod 777 /etc/profile
}

and added an echo so that I can see if it is actually running.

It is not:

# System-wide .profile for sh(1)

echo "test_global"

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi

I do not see the echo when I open up a bash shell.

  • 2
    `chmod 777` -> nonononono! Never ever run `chmod 777`. It is practically never required! Not even for "testing purposes". If the file is readable, then it's readable. If it's writable by the `user` or `group` that need to write to it, then it's writable. There is absolutely zero need to give everyone write permissions, and forgetting to `chmod` it back to something sane is exactly how multinationals get hacked. Just don't do it. Ever. I wrote [an introduction of Unix permissions](http://stackoverflow.com/a/35895436/660921). Please read it! – Martin Tournoij Mar 13 '16 at 04:15
  • Did you change your default shell? What does `echo $SHELL` report? – mklement0 Mar 13 '16 at 05:05

1 Answers1

3

/etc/profile is only invoked for login shells. To force a login shell vice an non-login shell add --login.

bash --login

When Bash is invoked as a login shell, or as a non-login shell with the --login option, 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.

Brian Mc
  • 141
  • 8
  • See also https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html – tripleee Mar 13 '16 at 06:58
  • @chrisahearn if you are only concerned about setting things up for yourself, you could put a source link to /etc/profile in your .bash_profile. This will tell bash to load both profiles into memory when you launch a shell. – Brian Mc Mar 14 '16 at 00:54
  • The problem is, is that I'm running `sudo su` and I don't know how to make it run some sort of initialization script. –  Mar 15 '16 at 20:55
  • In fact I don't know if it is considered a login shell - http://stackoverflow.com/questions/36021699/is-there-a-sytem-wide-initialization-file-for-non-login-shells –  Mar 15 '16 at 20:56