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
Usage examples
Source a trusted settings file
source ./project.envThe environment script executes in the current shell, with all actions permitted to that account.
Use POSIX syntax
. ./project.envThe dot command performs the shell's sourcing operation using the selected file.
Check syntax before sourcing
bash -n ./project.envBash 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.