Around 2015, then on Debian Jessie, I wrote a shell snippet
~/.shenv that gets sourced from startup configuration for different shells and sets environment variables. I'm still using it today. At the top, it contains a lengthy comment about how different pieces of environment come together. While I updated it from time to time, it may be not quite up-to-date and should be taken with a grain of salt. Here is the said comment:
Code: Select all
# Common environment for POSIX-compliant shells/xsession
# This file gets sourced from ~/.profile for login POSIX-conform shells,
# i.e. dash, posh, ksh93, mksh always and bash, yash, zsh when in POSIX mode
# (or from ~/.{bash_,yash_,z}profile for bash, yash, zsh in their native modes,
# respectively).
# Fo GUI logins it gets sourced from ~/.xsessionrc instead
# Do not confuse it with ~/.zshenv that gets invoked by zsh both for inter-
# active and non-interactive shells. A non-interactive shell usually needs
# some variables defined, too, e.g. PATH, HOSTNAME, USER, LOGNAME, LANG et al.
# Most of them are taken care of in some other place like
# /etc/locale.conf, /etc/environment, /etc/security/pam_env.conf, etc.
#/etc/security/pam_env.conf sets nothing by default
#/etc/environment sets nothing by default
#$HOME/.pam_environment currently not used
#/etc/pam.d/{fingerprint,password,system}-auth call 'auth required pam_env.so'
#/etc/pam.d/{atd,gdm-launch-environment} also call 'auth required pam_env.so'
#/etc/locale.conf sets $LANG ($LC_{NUMERIC,TIME,MONETARY,PAPER,MEASUREMENT})
#$HOME/.i18n sets nothing by default ($LC_ALL may go here)
## login
#/etc/login.defs sets no env vars by default (not even $MAIL)
# pam_mail.so could also set $MAIL, but never used in /etc/pam.d/*
# login uses /etc/login.defs and starts login shell ($SHELL)
# Starting console sets $TERM
# bash sets [E]UID internally
#/etc/profile sets PATH, USER=$LOGNAME, MAIL, HOSTNAME, HISTSIZE, HISTCONTROL
# Some /etc/profile.d scriptlets:
# flatpak.sh sets $XDG_DATA_DIRS
# lang.sh sets vars from /etc/locale.conf and $HOME/.i18n
# less.sh sets LESSOPEN (user-defined filters go to ~/.lessfilter)
# modules.sh sources /usr/share/Modules/$shell
# $shell scripts set ENV,BASH_ENV,PATH,MANPATH (ksh, zsh also set FPATH)
# they also set initial values for MODULESHOME, MODULEPATH, LOADEDMODULES
# scl-init.sh sets MODULESHOME, augments MODULEPATH
# vte.sh sets PROMPT_COMMAND unconditionally under bash (duh!)
# sh.local gets sourced at last (empty by default)
# for bash, /etc/bashrc gets sourced (non-login bash initializations):
# interactive?
# set PROMPT_COMMAND if not already set
# for non-login xterm|vte: to /etc/sysconfig/bash-prompt-xterm
# for screen: to /etc/sysconfig/bash-prompt-screen
# otherwise: to /etc/sysconfig/bash-prompt-default
# non-login?
# set $SHELL
# source /etc/profile.d/*.sh
# PROMPT_COMMAND gets redefined by vte.sh (duh!),
# sh.local doesn't get sourced (duh!).
## GUI login: $HOME/.xsessionrc is sourced
## Already set at this point: $HOME, $USER, $LOGNAME, $SHELL
# Starting a terminal emulator (xterm, rxvt etc.) sets $TERM
# Note: /etc/mkshrc sets and exports $SHELL. It's only an example of user
# shell resource file ~/.mkshrc and never gets executed on its own.
# $LINES and $COLUMNS get set for non-interactive shells by zsh and mksh only.
# They can be set from a shell script by `tput lines` and `tput cols`
# provided $TERM is set beforehand, which is usually the case if the script
# is called from the console or terminal emulator. Setting them when you are
# NOT in a terminal makes little sense anyway.
# Alternatively, they can be set from `stty size`, but I'm not aware of a ter-
# minal emulator not setting $TERM on start.