Bash 5 reference · Shell Builtins and Syntax
source (Bash builtin)
Run a file's commands in the current shell, so its variables and functions stay defined; . is the POSIX spelling.
Bash 5
Syntax
source FILE [ARGS] . FILE
Parameters
| Parameter | Description |
|---|---|
FILE |
Path to a script, often a config or library file. |
Examples
printf 'APP=shop\nport=8080\n' > app.env
source ./app.env
echo "$APP on $port"
Output
shop on 8080
Run this on your computer — see “Get Started” for setup.
echo 'greet() { echo "hi $1"; }' > lib.sh
. ./lib.sh
greet Ana
Output
hi Ana
Run this on your computer — see “Get Started” for setup.
Only source files you trust: they run with your permissions. For untrusted configuration, parse it instead.
Related
export· Mark variables so child processes inherit them; one-off variables can also be set for a single command.- Bash Environment Variables and PATH · tutorial