Originally Posted by ruario
I know they can be sourced but in Slackware at least the /etc/profile.d files are only sourced if they are executable, see the earlier code snippet from Slackware's default /etc/profile. Granted this may be different in other distros so without further testing, removing read permissions may be a safer bet.
-x checks for execute permissions.
Just checked Debian. The equivalent is
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
(Wouldn't that break if there were whitespace in the names in the /etc/profile.d/*.sh expansion?)
To be certain, tested for execute only permission ...
c@CW8:/tmp$ echo 'echo running!' > foo
c@CW8:/tmp$ chmod 100 foo
c@CW8:/tmp$ source foo
bash: foo: Permission denied
... and confirmed it is the read permission that matters.