Linux shell startup files: Which system-wide script sets default environment variables and startup behavior for all users when they log in to a Bash shell?

Difficulty: Easy

Correct Answer: /etc/profile

Explanation:


Introduction / Context:
Understanding Bash startup files is essential for Linux system administration. Different files are sourced depending on whether a shell is a login or non-login shell and whether the configuration is system-wide or per-user. This question targets the system-wide file that establishes default environment settings for all users at login.



Given Data / Assumptions:

  • Bash is the default shell considered.
  • We are concerned with global defaults that apply to all users.
  • The context is a login shell (for example, when a user logs in via console, SSH, or a display manager starting a login shell).


Concept / Approach:

Bash distinguishes between system-wide and per-user initialization files. For login shells, Bash reads /etc/profile first (system-wide) and then looks for per-user files like ~/.bash_profile, ~/.bash_login, or ~/.profile. For interactive non-login shells, many distributions use /etc/bash.bashrc or /etc/bashrc plus the user's ~/.bashrc. Only one of the options given is the canonical system-wide login file.



Step-by-Step Solution:

Identify the system-wide login initialization file: /etc/profile.Confirm that hidden variants like /etc/.profile are non-standard in Linux distributions.Recognize that /etc/.bashrc is also non-standard; common names are /etc/bash.bashrc or /etc/bashrc, not listed here.Discard unrelated paths like /etc/.log.


Verification / Alternative check:

On a typical Linux system, run man bash and review the INVOCATION section, which explains that login shells read /etc/profile. Distribution documentation (Debian/Ubuntu, RHEL/Fedora) confirms this behavior.



Why Other Options Are Wrong:

  • /etc/.profile: Not a standard global login file; misleading due to the dot prefix.
  • /etc/.bashrc: Not standard; most systems use /etc/bash.bashrc or /etc/bashrc for non-login shells.
  • /etc/.log: Not a configuration file for shells.
  • None of the above: Incorrect because /etc/profile is correct.


Common Pitfalls:

Confusing system-wide files with per-user dotfiles (for example, ~/.bashrc). Also, mixing up login and non-login shell behavior leads to incorrect assumptions about which file executes. Always consider shell type and distribution conventions.



Final Answer:

/etc/profile

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion