I heard through the grapevine that files in /etc/profile will be automatically sourced by bash upon login?
I tried writing something simple to /etc/profile:
echo "echo 'foo'" > /etc/profile/foo.sh
but I got this weird error:
bash: /etc/profile/foo.sh: Not a directory
is there a correct way to do this?
Best Answer
/etc/profile
is a file. Hence the error when trying to create/etc/profile/foo.sh
./etc/profile.d
is the directory you're thinking of. Scripts placed in there get sourced on login. In your example, you'd want to create/etc/profile.d/foo.sh
.The script logic behind this and how it's pulled in can be seen below. Similar code is in
/etc/profile
,/etc/bashrc
,/etc/csh.cshrc
and/etc/csh.login
.Example of creating and invoking such a script:
More information at What do the scripts in /etc/profile.d do?