Priority of shell environment configuration file on linux
Priority of shell environment configuration file on linux
Interactive: As the term implies: Interactive means that the commands are run with user-interaction from keyboard. E.g. the shell can prompt the user to enter input.
Non-interactive: the shell is probably run from an automated process so it can't assume it can request input or that someone will see the output. E.g., maybe it is best to write output to a log file.
Login: Means that the shell is run as part of the login of the user to the system. Typically used to do any configuration that a user needs/wants to establish his work environment.
Non-login: Any other shell run by the user after logging on, or which is run by any automated process which is not coupled to a logged in user.
PS1 is set and $- includes i, if bash is interactive.
shopt login_shell is on, if bash is login.
flowchart TD
Start[Shell Invocation] --> LoginInteractive;
Start --> NonLoginInteractive;
Start --> NonLoginNonInteractive[Non-Login Non-Interactive Shell<br>Inherits Parent Environment];
subgraph LoginInteractive [Login Interactive]
direction TB
subgraph GlobalFiles [System-wide Files]
G1["/etc/profile"] --> G2["/etc/profile.d/*.sh"];
style GlobalFiles fill:#e1f5fe,stroke:#01579b,stroke-width:2px
end
subgraph UserFiles [User Files]
U1["~/.bash_profile"] --> U2["~/.bash_login"];
U2 --> U3["~/.profile"];
U3 --> U4["~/.bashrc"];
style UserFiles fill:#f3e5f5,stroke:#4a148c,stroke-width:2px
end
style LoginInteractive fill:#fafafa,stroke:#424242,stroke-width:2px
G2 -.-> U1;
end
subgraph NonLoginInteractive [Non-Login Interactive]
direction TB
NL1["~/.bashrc"] --> NL2["/etc/bash.bashrc"];
style NonLoginInteractive fill:#f1f8e9,stroke:#33691e,stroke-width:2px
end
subgraph Logout
direction LR
LL1["~/.bash_logout"];
style Logout fill:#ffebee,stroke:#b71c1c,stroke-width:2px
end
LoginInteractive -- Exit Shell --> Logout;
style Start fill:#e8f5e8,stroke:#2e7d32,stroke-width:2px
style NonLoginNonInteractive fill:#fff3e0,stroke:#ef6c00,stroke-width:2px