Interactive vs Non-Interactive Shells

Updated

October 31, 2026

Interactive vs Non-Interactive Shells

Bash operates differently depending on whether it is running interactively (attached to a terminal prompt) or executing a non-interactive automation script:

Feature Interactive Shell Non-Interactive Script
$- flag string Contains i Lacks i
Aliases Enabled by default Disabled (must shopt -s expand_aliases)
Job control (set -m) Enabled Disabled by default
Config files loaded ~/.bashrc Non-login loads $BASH_ENV
History expansion (!) Enabled Disabled
# Check if running interactively
if [[ $- == *i* ]]; then
    echo "Running interactively"
else
    echo "Running non-interactively in automation"
fi