What is the difference between executing a script (e.g. /some/script) with source /some/script and . /some/script in Bash?
Asked
Active
Viewed 7.1k times
2 Answers
156
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.
avpaderno
- 297
52
. 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,477