io

source (.)

Executes FILE in the CURRENT shell (no subshell), so variables, functions, and aliases defined in it persist. Contrast with 'bash file' which runs in a child process — its side effects vanish when it exits.

source FILE [ARGS]   |   . FILE [ARGS]

Common flags / operators

Flag / Operator Purpose
source Bash-preferred keyword form
. POSIX form — identical behavior, works in sh
ARGS Become positional parameters ($1, $2, ...) inside the file
search path Uses $PATH if FILE has no slash and 'sourcepath' shopt is on

Examples

source ~/.bashrc

Reload your bashrc into the current session.

. ./venv/bin/activate

Activate a Python virtualenv (POSIX-portable form).

source config.env

Load KEY=value pairs as variables in the current shell.

source lib.sh --verbose

Sourced file sees --verbose as $1 inside.

Gotcha

'return' inside a sourced file exits the source but not the shell; 'exit' would kill the whole shell. Sourcing untrusted files is dangerous — they run with your full shell privileges.

Related

← All Bash builtins · Linux commands