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

NameTypeDescription
filenamepathTrusted shell file to read.
argumentsstring listOptional 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
Bash Reference