HOME

TheInfoList



OR:

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 Command may refer to: Computing * Command (computing), a statement in a computer language * command (Unix), a Unix command * COMMAND.COM, the default operating system shell and command-line interpreter for DOS * Command key, a modifier key on A ...
that
eval In some programming languages, eval , short for 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 been incl ...
uates 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 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 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 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 th ...
, the shell will search for the file in all directories 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 * Desir ...
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 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, 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 Module, modular and modularity may refer to the concept of modularity. They may also refer to: Computer science and engineering * Modular design, the engineering discipline of designing complex devices using separately designed sub-components ...
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 A dot is usually a small, round spot. Dot, DoT or DOT may also refer to: Orthography * Full stop or "period", a sentence terminator * Dot (diacritic), a mark above or below a character (e.g. ȧ, ạ, İ, Ċ, ċ, etc.), usually to indicate sou ...
(.) in 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 In computing, Bash (short for "''Bourne Again SHell''") is an interactive command interpreter and command programming language developed for UNIX-like operating systems. Created in 1989 by Brian Fox for the GNU Project, it is supported by the Fre ...
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 (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