According to the bash man page:
The following paragraphs describe how bash executes its startup files. If any of the files exist but cannot be read, bash reports an error. Tildes are expanded in filenames as described below under Tilde Expansion in the EXPANSION section.
When bash is invoked as an interactive login shell, or as a non-interactive 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. The --noprofile option may be used when the shell is started to inhibit this behavior.
/etc/profile.d/ is technically not in the spec, but its name clearly implies it is intended to only be sourced in /etc/profile. And sure enough, this is what Arch, Ubuntu, Debian and OpenSUSE do (though Debian has lines commented out which would allow sourcing it in bashrc with a warning that enabling it could cause issues).
Fedora however ships the following in /etc/bashrc:
...
SHELL=/bin/bash
# Only display echos from profile.d scripts if we are no login shell
# and interactive - otherwise just process them to set envvars
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
...
This behaviour is arguably spec-breaking and out of line with other distros. This repo relies on it as /etc/profile.d/brew.sh specifically early exits if not run from an interactive shell - and from what I understand, that means the only shell in which this should execute is the TTY when logging in from there.
I am unsure what the best solution is to ensuring that interactive shells execute this code without overwriting potentially important files like /etc/bashrc - in fact I imagine this problem is why Fedora does things this way in the first place.
According to the bash man page:
/etc/profile.d/is technically not in the spec, but its name clearly implies it is intended to only be sourced in/etc/profile. And sure enough, this is what Arch, Ubuntu, Debian and OpenSUSE do (though Debian has lines commented out which would allow sourcing it in bashrc with a warning that enabling it could cause issues).Fedora however ships the following in
/etc/bashrc:This behaviour is arguably spec-breaking and out of line with other distros. This repo relies on it as
/etc/profile.d/brew.shspecifically early exits if not run from an interactive shell - and from what I understand, that means the only shell in which this should execute is the TTY when logging in from there.I am unsure what the best solution is to ensuring that interactive shells execute this code without overwriting potentially important files like
/etc/bashrc- in fact I imagine this problem is why Fedora does things this way in the first place.