What is the difference between executing a script (e.g. /some/script) with source /some/script
and . /some/script
in Bash?
Asked
Active
Viewed 6.7k times
171
2 Answers
153
source
and .
are synonymous in Bash.
For anyone who might like to verify that the commands are simply synonyms and nothing more, look at the source code, say for version 4.3, and examine the file builtins/source.def
. You will read that both of the built-in commands, source
and .
, use the very same function: source_builtin
.

apaderno
- 289
50
.
is synonymous with source
in bash, but not in POSIX sh, so you should use .
if your script is run by /bin/sh. Note that bash claims to run like POSIX sh when called as /bin/sh, but accepts source
without complaint.
This behaviour has bitten me, scripts tested with bash as /bin/sh fail when run under ash, for example.

jjg
- 1,427
-
17POSIX does not restrict the shell. POSIX just says; the shell shall support at least this and that feature. So a POSIX shell is free to implement additional features as long as the ones described by POSIX are implemented. When the shebang says
#!/bin/sh
you should never assume the shell supports anything but POSIX features though. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18 – geirha Feb 09 '11 at 23:51 -
You may be affected by the order of looking names up: http://unix.stackexchange.com/q/17815/8250 – Lekensteyn Jul 16 '12 at 11:05
-
3
.
is the traditional source command, inherited from the ancient bourne shell.source
is just a bash builtin that does exactly the same as.
, presumably because it's more readable (a.
alone may be hard to spot with a small font). You'll seehelp source
andhelp .
shows the same info. – geirha Feb 09 '11 at 23:56man bash
and then search forsource
you'll see thatsource filename [arguments]
is a synonym for. filename [arguments]
. – Matthew Rankin Feb 17 '11 at 12:22