In a Unix shell, the full stop called the dot command (.) is a command that evaluates commands in a computer file in the current execution context. In C Shell, a similar functionality is provided as the
source command, and this name is seen in "extended" POSIX shells as well.
The dot command is not to be confused with a dot file, which is a dot-prefixed hidden file or hidden directory. Nor is it to be confused with the
./scriptfile notation for running commands, which is simply a relative path pointing to the current directory (notated in Unix as a '.' character, and typically outside of the Path variable).
The filename is the dot command's first argument. When this argument does not contain a slash, the shell will search for the file in all directories defined in the PATH environment variable. Unlike normal commands which is also found in PATH, the file to source does not have to be executable. Otherwise the filename is considered as a simple path to the file.
In several "extended" shells including bash, zsh and ksh, one may specify parameters in a second argument. If no parameters are specified, the sourced file will receive the set of positional parameters available in the current context. If parameters are specified, the sourced file will receive only the specified parameters. In any case, parameter
$0 will be the
$0 of the current context.
Since the execution of the source file is done in the invoking context, environment[a] changed within apply to the current process or the current shell. This is very different from scripts run directly by shebang or as
sh foo.sh, which are run in a new, separate process space, with a separate environment.
Therefore, the dot command can be used for splitting a big script into smaller pieces, potentially enabling modular design. Sourcing is also often done by the shell on session startup for user profile files like
- source (command)
- See Shell Execution Environment in POSIX.1:2013.
- "POSIX.1:2013 Shell Command Language § dot". Retrieved 23 May 2016.
- "Csh man page#command". Retrieved 23 May 2016.
- "Bash Reference Manual § Bourne Shell Builtins". Retrieved 23 May 2016.
- "ZSH Shell Builtin Commands". Retrieved 23 May 2016.
- "ksh man page". Oracle. Retrieved 23 May 2016.
+ . name [arg ...]