Source vs . why different behaviour?

You can't just replace . with source everywhere; if

. ./.a.a

works, you can replace the first . (at least in Bash):

source ./.a.a

The second . represents the current directory, you can't replace that with source (especially not ./ with source as you've done).

source source

would be OK if you had a file called source in the current directory, containing something meaningful for your current shell. I can't see how . . would be OK...

Also, . ./.a.a and ./.a.a aren't the same, the second form runs .a.a in a separate shell. See What is the difference between sourcing ('.' or 'source') and executing a file in bash? for details.


source is a shell keyword that is supposed to be used like this: sourcefile where file contains valid shell commands. These shell commands will be executed in the current shell as if typed from the command line. Now, .file does exactly the same.

Beyond that . alone means "the current working directory" as in ./xyz ("xyz in this directory") or a/b/./c/./d (which is identical to a/b/c/d).

Beyond that . in a filename has a meaning only by convention as in .foobar which indicates a "hidden" file (not really...) or as in foobar.pdf, which indicates a file format by the suffix (here .pdf).

These different meanings cannot be interchanged.

Tags:

Bash