{{Short description|Unix command}} {{Distinguish|DOT (graph description language)}} 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.<ref name=posix2013>{{cite web|title=POSIX.1:2013 Shell Command Language § dot|url=http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#dot|access-date=23 May 2016}}</ref> In the C shell, a similar functionality is provided as the <code>source</code> command,<ref name="cshman">{{cite web|title=Csh man page#command|url=https://docs.oracle.com/cd/E19683-01/816-0210/6m6nb7m71/index.html#Commands|access-date=23 May 2016}}</ref> and this name is seen in "extended" POSIX shells as well.<ref name=bashref/><ref name=zshdoc/>
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 <code>./scriptfile</code> 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).
== Arguments ==
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 are 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.<ref name=posix2013/>
In several "extended" shells including bash,<ref name="bashref">{{cite web|title=Bash Reference Manual § Bourne Shell Builtins|url=https://gnu.org/s/bash/manual/bashref.html#Bourne-Shell-Builtins|access-date=23 May 2016}}</ref> zsh<ref name="zshdoc">{{cite web|title=ZSH Shell Builtin Commands|url=https://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html|access-date=23 May 2016}}</ref> and ksh,<ref name="oracleksh93">{{cite web|title=ksh man page|url=https://docs.oracle.com/cd/E36784_01/html/E36870/ksh-1.html|publisher=Oracle|access-date=23 May 2016|quote=+ . name [arg ...]}}</ref> 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 <code>$0</code> will be the <code>$0</code> of the current context.
== Usages == Since the execution of the source file is done in the invoking context, environment{{NoteTag|See [http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_12 Shell Execution Environment] in POSIX.1:2013.}}, changes within apply to the current process or shell. This is very different from scripts run directly by shebang or as <code>sh foo.sh</code>, 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 <code>.bashrc</code> and <code>.profile</code>.
==<code>source</code>== '''<code>source</code>''' is a shell-builtin command that evaluates the file following the command, as a list of commands, executed in the current context.<ref>"BASH BUILTIN COMMANDS", the Linux man page for "source" in Bash-3.0. 2004 Apr 20</ref> Frequently the "current context" is a terminal window into which the user is typing commands during an interactive session.
The source command can be abbreviated as just a dot (<code>.</code>) in Bash and similar POSIX-ish shells. However, this is not acceptable in C shell, where the command first appeared.
Some Bash scripts should be run using the <code>source your-script</code> syntax rather than run as an executable command, e.g., if they contain a change directory (<code>cd</code>) command and the user intends that they be left in that directory after the script is complete, or they contain an export command and the user wants to modify the environment of the current shell. Another usage situation is when a script file does not have the "execute" permission. Passing the script filename to the desired shell will run the script in a subshell, not the current context.
== Notes == {{NoteFoot}}
== References == {{reflist}}
==External links== * [https://web.archive.org/web/20110311131157/http://www.howtoguides.com/computers/os/unix/shell/dot.mobile.html The three different uses of the dot in Unix explained]
{{Unix commands}}
Category:Standard Unix programs Category:Unix SUS2008 utilities Category:IBM i Qshell commands