Apply common environment initialization to users of login shells, before user-specific files.
Which file is appropriate?
/etc/profile is the system-wide initialization file for login shells and is processed before user login files.
Detailed explanation
~/.bashrcIncorrect. ~/.bashrc is a per-user interactive setting.
Incorrect. ~/.bashrc is a per-user interactive setting.
~/.bash_profileIncorrect. ~/.bash_profile is a per-user login setting.
Incorrect. ~/.bash_profile is a per-user login setting.
/etc/profileCorrect. /etc/profile provides system-wide login-shell initialization.
Correct. /etc/profile provides system-wide login-shell initialization.
/etc/skelIncorrect. /etc/skel is a template copied into new homes, not directly executed at login.
Incorrect. /etc/skel is a template copied into new homes, not directly executed at login.
Try it yourself
An example you can run in a temporary verification environment.
test -r /etc/profile && sed -n '1,8p' /etc/profileExpected result
/etc/profileの先頭部分。内容はディストリビューションで異なるKey points
- /etc/profile is system-wide
- Login startup
- Before user files
Notes
- Environment: GNU Bashを使用するLinux / 読み取り操作
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.