Login shell
Whenever bash/zsh/etc was launched with the --login
flag or by the systemd/init process determines whether it is a “login shell” (although because there’s two ways to create this, figuring out if you are in a login shell isn’t 100%.
These will run the first readable profile script they encounter. The specific shell determines where it looks but for (some versions) of bash for example the order is .bash_profile
, .bash_login
, .profile
. This varies by version a bit but isn’t too terribly hard to guess. Also there are logout scripts that will run on shell exit (their names are similar but not completely homoiconic). All this can be disabled with --noprofile
Interactive non-login shell
When launched with -i
(which is not short for --interactive
but instead a shopt thing) or I believe via just bash
/zsh
without the -c
parameter, This is again not straightforward to test for whether you’re interactive or not. Online people say to check for echo $-
containing an i
but I