Login, interactive and noninteractive shells
Bash has two independent startup properties: login mode and interactivity. Login mode describes how the shell was invoked; interactive mode describes whether it accepts commands interactively (or was explicitly started with -i). Test interactivity with [[ $- == *i* ]] and login mode with shopt -q login_shell. A script normally runs noninteractively, but bash --login -c ... requests a noninteractive login shell.
For normal Bash invocation, login startup reads /etc/profile and then the first readable file among ~/.bash_profile, ~/.bash_login, ~/.profile. An interactive non-login shell normally reads ~/.bashrc; a login profile may explicitly source that file. Distributions may add system-wide rc files. --noprofile skips login profiles; --norc skips the interactive rc startup; --rcfile file selects an alternative interactive rc file. Neither suppression flag is a complete environment reset. Ordinary noninteractive Bash uses BASH_ENV (next lesson). An interactive login shell may also execute ~/.bash_logout at exit. Invocation as sh, POSIX mode, remote shell detection and unequal effective/real IDs have special rules: do not infer them from this basic matrix. When invoked as sh, an interactive shell uses ENV and login startup uses /etc/profile and ~/.profile; POSIX startup uses ENV for interactive shells. Restricted Bash (-r) limits some operations but is not a security sandbox. These tests skip actual system and personal profile execution. The startup examples use env -i to omit inherited BASH_ENV as well as --noprofile and --norc. This tests invocation flags, not actual login profile selection or terminal behavior.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code.
Detect noninteractive execution
env -i PATH=/usr/bin:/bin HOME="$PWD" LC_ALL=C /bin/bash --noprofile --norc -c 'if [[ $- == *i* ]]; then printf "interactive\n"; else printf "noninteractive\n"; fi' Expected stdout:
noninteractiveThe command string runs without interactive mode.
Compare login flags safely
env -i PATH=/usr/bin:/bin HOME="$PWD" LC_ALL=C /bin/bash --noprofile --norc -c 'if shopt -q login_shell; then echo login; else echo nonlogin; fi'env -i PATH=/usr/bin:/bin HOME="$PWD" LC_ALL=C /bin/bash --noprofile --norc --login -c 'if shopt -q login_shell; then echo login; else echo nonlogin; fi' Expected stdout:
nonloginloginThe second child requests login mode but suppresses profiles.
Pass arguments to a command string
env -i PATH=/usr/bin:/bin HOME="$PWD" LC_ALL=C /bin/bash --noprofile --norc -c 'printf "%s\n" "$0" "$1"' report 'daily report' Expected stdout:
reportdaily reportAfter the command string the next argument supplies $0, not $1.
Common mistakes
Do not assume every login shell is interactive or every interactive shell is a login shell. Do not edit actual dotfiles to investigate startup order.
Practice
In a fresh private directory compare bash -c with bash --noprofile --norc --login -c using shopt -q login_shell. Explain why neither is interactive. Predict which files would normally be read without suppression; do not run the real profiles.
Next: BASH_ENV and startup safety