为什么点 (.) 被用作源的别名 & 为什么其他命令也没有快捷方式?

Arn*_*lle 8 shell bash historical-unix

编辑:实际上,它不是别名(见答案)

众所周知,在 shell 中,点命令 ( .) 是源命令的别名。

但我想知道这样一个奇怪的别名背后是否有原因?显然,我不经常使用它,所以我需要这么短的别名。

那么,为什么是一个点呢?为什么 forsource而不是更常用的命令,例如cdls?为什么甚至是别名?这背后有什么好的理由吗?还是有历史原因?

注意:我最初在 Server Fault 上发布了这个问题,但有人建议我将其发布在这里。

jes*_*e_b 13

.POSIX 标准

source是 bash 内置的同义词,.并且不像.

此外,在击参考手册记.下列出4.1 Bourne Shell的内置命令source下列出4.2击内置命令为:

的同义词。(请参阅 Bourne Shell 内置程序)。

bash 命名它是可能的,source因为这就是它在 C shell 中的名称(该命令显然来自于此)。

  • @schily:我哪里说了相反的话? (2认同)

slm*_*slm 5

就 Bash 而言,.source不是其中之一的别名,这是一个简单的事实,它们都是调用相同底层函数的内置函数,source_builtin

\n\n

看看source.defBash 源代码中的文件:

\n\n
$PRODUCES source.c\n\n$BUILTIN source\n$FUNCTION source_builtin\n$SHORT_DOC source filename [arguments]\nExecute commands from a file in the current shell.\n\nRead and execute commands from FILENAME in the current shell.  The\nentries in $PATH are used to find the directory containing FILENAME.\nIf any ARGUMENTS are supplied, they become the positional parameters\nwhen FILENAME is executed.\n\nExit Status:\nReturns the status of the last command executed in FILENAME; fails if\nFILENAME cannot be read.\n$END\n\n$BUILTIN .\n$DOCNAME dot\n$FUNCTION source_builtin\n$SHORT_DOC . filename [arguments]\nExecute commands from a file in the current shell.\n\nRead and execute commands from FILENAME in the current shell.  The\nentries in $PATH are used to find the directory containing FILENAME.\nIf any ARGUMENTS are supplied, they become the positional parameters\nwhen FILENAME is executed.\n\nExit Status:\nReturns the status of the last command executed in FILENAME; fails if\nFILENAME cannot be read.\n$END\n
Run Code Online (Sandbox Code Playgroud)\n\n

参考

\n\n\n