What is the difference between "source" and "."?

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.


. 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.

Tags:

Bash

Scripts