Shell and environment

Command source

Execute file in current shell session

Linux · Bash examples · commands run on the selected server

When to use source

Use source only with trusted shell code. It executes the file in the current shell and can change variables, functions, working directory and other state; it is not a harmless data-file parser.

Syntax

source FILE [ARGUMENTS...]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

FILE
Path to the script running in the current shell.
. FILE
POSIX-compatible syntax for sourcing a file.

Usage examples

Source a trusted settings file

source ./project.env

The environment script executes in the current shell, with all actions permitted to that account.

Use POSIX syntax

. ./project.env

The dot command performs the shell's sourcing operation using the selected file.

Check syntax before sourcing

bash -n ./project.env

Bash checks syntax without executing the script; successful syntax does not prove it is safe.

Notes and limitations

  • source executes commands; it does not merely read key-value pairs. Only source trusted files.
  • Variable, directory and function changes remain in the current shell. Not every /bin/sh supports source.

Common questions and troubleshooting

Is it safe to source a downloaded environment file?

Only if you trust and have reviewed it. Shell code can execute arbitrary commands even when its filename suggests it only contains settings.

Why are variables not available to child programs afterward?

Sourcing assigns variables but does not automatically export every assignment. Export only the values that child processes actually need.

Further help

Options vary by version and distribution. Check the installed documentation with this command: help source.