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
exec
Replaces the current shell process with COMMAND (no new process is created). Without a command, applies redirections permanently to the current shell — a common way to open long-lived file descriptors.
return
Exits a shell function or sourced script and returns exit status N (0-255). Without N, returns the exit status of the last command executed in the function.
export
Marks a shell variable (or function with -f) for export to the environment of subsequently executed commands. Without arguments, prints all exported variables in a re-importable format.
echo
Writes arguments to stdout separated by spaces and terminated with a newline. Behavior across systems is inconsistent (especially escape processing) — prefer printf for anything with formatting or portability requirements.
printf
Formats and prints arguments according to a C-style format string. Portable, precise, and reuses the format string if extra arguments are provided — the preferred replacement for echo when you need formatting.