HOME

TheInfoList



OR:

In a
Unix shell A Unix shell is a command-line Interpreter (computing), interpreter or shell (computing), shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting langua ...
, the
full stop The full stop (Commonwealth English), period (North American English), or full point , is a punctuation mark. It is used for several purposes, most often to mark the end of a declarative sentence (as distinguished from a question or exclamation ...
called the dot command (.) is a
command Command may refer to: Computing * Command (computing), a statement in a computer language * COMMAND.COM, the default operating system shell and command-line interpreter for DOS * Command key, a modifier key on Apple Macintosh computer keyboards * ...
that
eval In some programming languages, eval , short for the English evaluate, is a function which evaluates a string as though it were an expression in the language, and returns a result; in others, it executes multiple lines of code as though they had b ...
uates commands in a
computer file A computer file is a computer resource for recording data in a computer storage device, primarily identified by its file name. Just as words can be written to paper, so can data be written to a computer file. Files can be shared with and transfe ...
in the current execution context. In
C Shell The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of the ...
, 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 A path is a string of characters used to uniquely identify a location in a directory structure. It is composed by following the directory tree hierarchy in which components, separated by a delimiting character, represent each directory. The del ...
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 directory structure. Different file systems impose different restrictions on filename lengths. A filename may (depending on the file system) include: * name &ndas ...
is the dot command's first
argument An argument is a statement or group of statements called premises intended to determine the degree of truth or acceptability of another statement called conclusion. Arguments can be studied from three main perspectives: the logical, the dialectic ...
. When this argument does not contain a
slash Slash may refer to: * Slash (punctuation), the "/" character Arts and entertainment Fictional characters * Slash (Marvel Comics) * Slash (''Teenage Mutant Ninja Turtles'') Music * Harry Slash & The Slashtones, an American rock band * Nash ...
, the shell will search for the file in all
directories Directory may refer to: * Directory (computing), or folder, a file system structure in which to store computer files * Directory (OpenVMS command) * Directory service, a software application for organizing information about a computer network's u ...
defined in the
PATH A path is a route for physical travel – see Trail. Path or PATH may also refer to: Physical paths of different types * Bicycle path * Bridle path, used by people on horseback * Course (navigation), the intended path of a vehicle * Desire p ...
environment variable An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs. For example, a running process can query the value of the TEMP env ...
. Unlike normal commands which are also found in PATH, the file to source does not have to be
executable In computing, 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), instructi ...
. 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 A parameter (), generally, is any characteristic that can help in defining or classifying a particular system (meaning an event, project, object, situation, etc.). That is, a parameter is an element of a system that is useful, or critical, when ...
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 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 Broadly speaking, modularity is the degree to which a system's components may be separated and recombined, often with the benefit of flexibility and variety in use. The concept of modularity is used primarily to reduce complexity by breaking a sy ...
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 Bash or BASH may refer to: Arts and entertainment * ''Bash!'' (Rockapella album), 1992 * ''Bash!'' (Dave Bailey album), 1961 * '' Bash: Latter-Day Plays'', a dramatic triptych * ''BASH!'' (role-playing game), a 2005 superhero game * "Bash" ('' ...
and similar POSIX-ish shells. However, this is not acceptable in
C shell The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of the ...
, where the command first appeared. Some
Bash script Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been used as the default login shell for most Linux distributions. Bash was ...
s should be run using the source your-script syntax rather than run as an executable command, e.g., if they contain a
change directory The command, also known as (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files. Implementations The command has been ...
(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 an ...
command and the user wants to modify the
environment Environment most often refers to: __NOTOC__ * Natural environment, all living and non-living things occurring naturally * Biophysical environment, the physical and biological factors along with their chemical interactions that affect an organism or ...
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