In a
Unix shell
A Unix shell is a Command-line_interface#Command-line_interpreter, command-line interpreter or shell (computing), shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command languag ...
, the
full stop
The full stop ( Commonwealth English), period (North American English), or full point is a punctuation mark used for several purposes, most often to mark the end of a declarative sentence (as distinguished from a question or exclamation).
A ...
called the dot command (.) is a
command that
evaluates commands in a
computer file
A computer file is a System resource, resource for recording Data (computing), data on a Computer data storage, computer storage device, primarily identified by its filename. Just as words can be written on paper, so too can data be written to a ...
in the current execution context.
In the
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).
Arguments
The filename
A filename or file name is a name used to uniquely identify a computer file in a file system. Different file systems impose different restrictions on filename lengths.
A filename may (depending on the file system) include:
* name – base ...
is the dot command's first argument
An argument is a series of sentences, statements, or propositions some of which are called premises and one is the conclusion. The purpose of an argument is to give reasons for one's conclusion via justification, explanation, and/or persu ...
. When this argument does not contain a slash, the shell will search for the file in all directories defined in the PATH environment variable
An environment variable is a user-definable value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the va ...
. Unlike normal commands which are also found in PATH, the file to source does not have to be executable
In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instruction (computer science), in ...
. 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.
Usages
Since the execution of the source file is done in the invoking context, environment, changes within apply to the current process or 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 .bashrc
and .profile
.
source
source
is a shell-builtin command that evaluates the file following the command, as a list of commands, executed in the current context.["BASH BUILTIN COMMANDS", the Linux man page for "source" in Bash-3.0. 2004 Apr 20] 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 (.
) 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 source your-script
syntax rather than run as an executable command, e.g., if they contain a change directory (cd
) command and the user intends that they be left in that directory after the script is complete, or they contain an export
An export in international trade is a good produced in one country that is sold into another country or a service provided in one country for a national or resident of another country. The seller of such goods or the service provider is a ...
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
References
External links
The three different uses of the dot in Unix explained
{{Unix commands
Standard Unix programs
Unix SUS2008 utilities
IBM i Qshell commands