source builtin
The builtin that runs a file's commands in the current shell instead of in a new one; the POSIX spelling is a single dot.
In more detail
Variables, functions and cd changes made by the file stay in your shell afterwards, which is how .bashrc and configuration files work. That is also its risk: a sourced file can change anything in your session. The file needs read permission only.
Examples
source settings.sh. ./settings.shRelated terms
- virtual environment — A self-contained folder with its own Python and its own installed packages, so each project's packages stay separate.
- shell — The program that reads the commands you type, runs them and shows the results; sh and bash are common ones.
- child process — A process started by another process, its parent, from which it inherits a copy of the environment and current directory.
- .bashrc — A file in your home directory that every new interactive bash reads at startup, used for aliases, functions and prompt settings.
- shell script — A text file of shell commands that runs them in order, top to bottom, as if you had typed them one by one.
Taught in
- Installing Ansible — Ansible Configuration Management at Scale
- Shebangs, Permissions And Three Ways To Run — Bash Scripting & Command Line Automation
- POSIX sh Versus Bash — Bash Scripting & Command Line Automation