Can someone explain the real-world usage of /etc/profile, profile.d, and bashrc?
Can anyone clearly explain the real-world usage of `/etc/profile`, `/etc/profile.d/`, and `/etc/bashrc` in Linux?
I’m getting confused between different explanations from ChatGPT and Gemini regarding login shells, non-login shells, interactive shells, and non-interactive shells.
From what I understood:
* `.bashrc` is mainly for interactive shell settings like aliases, prompts, etc. * `/etc/profile` and `/etc/profile.d/*.sh` are usually used for global environment variables like `PATH`, `JAVA_HOME`, `ORACLE_HOME`, etc.
But here is where I’m confused:
Some explanations say we should configure application paths and environment variables in `/etc/profile.d/` because they are needed system-wide.
But others say non-interactive or non-login shells (like cron jobs or scripts) do not automatically load `/etc/profile` or `.bashrc` at all.
So my doubts are:
- What is the actual real-world purpose of: * `/etc/profile` * `/etc/profile.d/` * `/etc/bashrc` * `.bash_profile` * `.bashrc`
- In enterprise environments, where should things like: * `PATH` * `JAVA_HOME` * aliases * prompt customization actually be configured?
- If cron jobs/scripts/services don’t automatically load these files, then why is `/etc/profile.d/java.sh` considered standard practice for Java setup?
- How do Linux admins usually handle environments for: * SSH users * cron jobs * systemd services * automation scripts
I’m trying to understand the practical production usage rather than only textbook explanations.