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.
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
. 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?
Yes . is identical to the
As always the first reference is the
man bash manual page where you can confirm your initial guess by searching for
…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.
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
Your answers in brief:
. absolute_path/mycommandsource the script file
mycommandthat is in the directory
absolute_path/. For further references read here
- Yes . and
- When needed, ask
bash shellitself. 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.
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.
help without parameter from the prompt give us:
GNU bash, version 4.1.2(1)…
These shell commands are defined internally.
helpto see this list.
help nameto find out more about the function name.
info bashto find out more about the shell in general.
man -k' orinfo’ to find out more about commands not in this list.
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.
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