builtin
Bash source — execute in current shell
Reads and executes commands from a trusted file in the current shell context. State changes may persist. The dot command is the portable spelling; filename search behavior depends on shell mode and options. Do not source untrusted files. Example prerequisite: in a fresh lab directory, create trusted-lab-settings.sh containing a single line: printf '%s\n' 'Trusted lab file'.
Formal Syntax & Structure
bash syntaxbash
source filename [arguments]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| filename | path | Trusted shell file to read. |
| arguments | string list | Optional positional parameters for the sourced file. |
Return Value
exit status
Status of the last command executed, or 0 if no commands execute; nonzero if the file cannot be read or found.
Working Example
Example Snippetbash
source ./trusted-lab-settings.sh