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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

source FILE [ARGS]   . FILE

Parameters

ParameterDescription
FILE Path to a script, often a config or library file.

Examples

Load settings
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.

Load functions from a library
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.

Was this page helpful?