Bourne shell login initialization — which file sets a user’s environment on login? In the classic Bourne shell and Bourne-compatible shells, which file in the user’s HOME directory is executed to initialize the environment at login?

Difficulty: Easy

Correct Answer: .profile

Explanation:


Introduction / Context:
When a user logs into a Unix system using a Bourne-compatible shell, the shell reads certain startup files to set environment variables, PATH, aliases, and other customizations. Recognizing which file is responsible is essential for troubleshooting login behavior and configuring user environments.



Given Data / Assumptions:

  • Login shell is Bourne-compatible (sh, ksh, bash in POSIX sh-mode).
  • The file resides in the user’s HOME directory.
  • We are discussing traditional login sequence (not necessarily non-login interactive shells).


Concept / Approach:

The classic Bourne shell reads $HOME/.profile for login shells. Korn shell also reads it; bash reads ~/.bash_profile or ~/.profile if the former is absent for login shells. Other files like .exrc configure vi, and .mbox is a mailbox file.



Step-by-Step Solution:

Identify the shell type: Bourne-compatible login shell.Know the initialization order: for a login shell, .profile is sourced.Recognize alternatives: bash-specific files may take precedence, but .profile remains the generic answer.Select .profile as correct.


Verification / Alternative check:

Run echo $SHELL to identify the shell. For bash, check man bash under INVOCATION; for sh/ksh, consult their manuals. You will see .profile mentioned for login shells.



Why Other Options Are Wrong:

  • .exrc: editors (vi/ex) configuration, not shell login.
  • lastlogin: not a standard user startup file.
  • .mbox: mailbox file used by mail clients.
  • None of the above: incorrect because .profile is correct.


Common Pitfalls:

Confusing .bashrc (non-login interactive) with .profile; forgetting that display managers or modern shells may load different files depending on login type; mixing csh (.login) conventions with Bourne shell behavior.


Final Answer:

.profile

More Questions from Unix

Discussion & Comments

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