Why was the dot (.) used as an alias for source & why don't other commands have shortcuts too?

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.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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

Solution 2

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

Solution 3

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…

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply