5

EDIT : actually, it is not an alias (see answers)

As you all know, in a shell, the dot-command (.) is an alias to the source command.

But I wonder if there's a reason behind such a weird alias? Apparently, I don't use it so often that I would need such a short alias.

So, why a dot? And why for source and not a more commonly used command such as cd or ls? Why even an alias? Is there a good reason behind that? Or is there a historical reason?

NOTE: I originally posted this question on Server Fault but I was suggested to post it here instead.

closed as primarily opinion-based by slm Jul 29 '18 at 3:35

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    You actually have it backwards – Jesse_b Jul 28 '18 at 19:51
  • 2
    . is not an alias in the first place; nor is it a secondary name. This question takes a falsehood as its premise and, as demonstrated by the answers so far, is unanswerable except to say that the question is wrong, as such loaded questions are. – JdeBP Jul 28 '18 at 22:11
  • @JdeBP Actually, I tried alias source and alias . in order to know which one was the alias of the other but got no response from the command line. Now I understand why. Hence, I supposed that . was the alias because it was the shortest. I edited the question to make it clearer that the question is actually wrong. I did not change the title because it would change the meaning of the answers. – Arnaud Denoyelle Jul 28 '18 at 22:16
  • The next question can be found in the list that I collected two years ago at superuser.com/questions/1136409/#comment1631506_1136409 . (-: – JdeBP Jul 28 '18 at 22:29
  • Possible duplicate - unix.stackexchange.com/questions/58514/… – slm Jul 29 '18 at 2:54
13

. is the POSIX standard.

source is a bash builtin synonym for . and is not as portable as .

Also note in the Bash reference manual . is listed under 4.1 Bourne Shell Builtins and source is listed under 4.2 Bash Builtin Commands as:

A synonym for . (see Bourne Shell Builtins).

It's possible that bash named it source because that's what it was called in C shell (where the command apparently originated).

  • 1
    Your answer is not correct, sorry. Dot is from the Bourne Shell and source is from csh, see my answer. – schily Jul 28 '18 at 21:45
  • 2
    @schily: Where did I say something contrary? – Jesse_b Jul 28 '18 at 21:46
  • 1
    @Jesse_b: he's saying that POSIX was introduced in the eighties, but dot predates that by a decade or so. So if you want to know why dot and not something else, POSIX doesn't explain that. Right, everybody? Actually I don't think schily's answer answers the question either, as written: it doesn't say anything about why "." was chosen rather than some other name. – Croad Langshan Jul 28 '18 at 21:57
  • 1
    Really seems the primary question here is So, why a dot?, and your other question is a duplicate. I'm genuinely not sure which if any of the subsidiary questions (which I think you would have better chosen to comment on or ignore) you're answering here... – Croad Langshan Jul 28 '18 at 22:04
  • 1
    @JdeBP yes I saw the other question, I just think you both misinterpreted this one. – Croad Langshan Jul 28 '18 at 22:05
3

As far as Bash is concerned the . and source are not aliases for one or the other, it's a simple fact that they're both builtins which call the same underlying function, source_builtin.

Take a look at the source.def file from the Bash source code:

$PRODUCES source.c

$BUILTIN source
$FUNCTION source_builtin
$SHORT_DOC 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.

Exit Status:
Returns the status of the last command executed in FILENAME; fails if
FILENAME cannot be read.
$END

$BUILTIN .
$DOCNAME dot
$FUNCTION source_builtin
$SHORT_DOC . 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.

Exit Status:
Returns the status of the last command executed in FILENAME; fails if
FILENAME cannot be read.
$END

References

2

The dot command was introduced by the Bourne Shell most likely in 1976.

The source command was introduced by the csh in 1977 or 1978.

So there is not an alias relation but two different names for an "invention" at the same time.

BTW: I can tell you why cd is named this way. The command previously had been called chdir, but this was too long (slow to type) for the upcoming 110 Baud modems in 1974...

  • 3
    source could be even older, since it was a command in the Michigan terminal system. – xenoid Jul 29 '18 at 0:21
  • source is an obvious name, but I doubt that Bill Joy did know the MTS. – schily Jul 29 '18 at 7:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.