What does `. /path/command` do? (Space after dot, absolute path)

From this guide to Bash completion we learn that in order for Bash to perform auto-completion one must perform . /etc/etc/bash_completion.d/foobar (note the space after .) in order for Bash completion to work.

$ /etc/bash_completion.d/ssh
bash: /etc/bash_completion.d/ssh: Permission denied
$ . /etc/bash_completion.d/ssh
$ ls -l /etc/bash_completion.d | grep ssh
-rw-r--r-- 1 root root   297 Jan 28 18:04 ssh

Is . a shortcut for the source command? If not, then what is it? It is impossible to google for, man source returns nothing, and apropos source and info source give so much irrelevant information that I cannot tell if what I’m looking for is in there. How might I even begin to RTFM to find the answer to this question myself?

Asked By: dotancohen

||

Yes . is identical to the source function.

As always the first reference is the man bash manual page where you can confirm your initial guess by searching for / source

…shell function or script executed with . or source…

is the first reference, but a bit further you find a section Shell Builtin Commands

. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell
environment and return the exit status of the last command executed
from filename. If filename does not contain a slash, file names in
PATH are used to find the directory containing filename. The file
searched for in PATH need not be executable. When bash is not in posix
mode, the current directory is searched if no file is found in PATH.
If the sourcepath option to the shopt builtin command is turned off,
the PATH is not searched. If any arguments are supplied, they become
the positional parameters when filename is executed. Otherwise the
positional parameters are unchanged. The return status is the status
of the last command exited within the script (0 if no commands are
executed), and false if filename is not found or cannot be read.

That fact it is a bash builtin function is the reason source doesn’t come with its own man page, which is why apropos failed.

Answered By: HBruijn

This dot “.” means reading and executing commands from the filename argument in the current shell context.
It is equivalent to source. This style is from Bourne shell, and please refer to
http://ss64.com/bash/source.html

Answered By: user94000

Your answers in brief:

  1. . absolute_path/mycommand source the script file mycommand that is in the directory absolute_path/. For further references read here
  2. Yes . and source are equivalent.
  3. When needed, ask help to bash shell itself. You will have an answer for built in commands.

Some words more
Often the most simple way is the most elusive too: we didn’t think we can ask help to the shell itself, when commands are defined internally.
With type . and type source we can notice that those are built-in commands.

Hastur@Cthulhu:~> type . source  
. is a shell builtin  
source is a shell builtin

Once that we know it, with help we can have some quick information about them.
The command help without parameter from the prompt give us:

GNU bash, version 4.1.2(1)…
These shell commands are defined internally.
Type help to see this list.
Type help name to find out more about the function name.
Use info bash to find out more about the shell in general.
Use man -k' orinfo’ to find out more about commands not in this list.

Meanwhile with help . as well as help source you obtain the same identical help:

source: source filename [arguments]
Execute commands from a file in the current shell.

Read and execute commands from FILENAME in the current shell.  The
entries in $PATH are used to find the directory containing FILENAME.
If any ARGUMENTS are supplied, they become the positional parameters
when FILENAME is executed.

Exit Status:
Returns the status of the last command executed in FILENAME; fails if
FILENAME cannot be read.

“The obvious is that which is never seen until someone expresses it simply.”K.Gibran

Answered By: Hastur
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.