在'. ~/.bashrc'中,第一个'.'代表当前目录。

我看到了一篇关于在.bashrc中修复别名的帖子。
他说,在你把别名放入.bashrc之后,你需要使用:
. ~/.bashrc

我不太明白这里的第一个点(' . ')具体是做什么用的。它的功能是什么,它叫什么名字?
2个回答

如果您想在bash中检查某些内容,请使用typeman
在您的情况下,您想知道什么是。
$ type .
. is a shell builtin

shell builtin 意味着 . bash shell 内部。您可以在 bash 手册页中找到有关shell builtins的信息。有一个很大的部分 SHELL BUILTIN COMMANDS
$ man bash

SHELL BUILTIN COMMANDS
       Unless otherwise noted, each builtin command documented in this section
       as accepting options preceded by - accepts -- to signify the end of the
       options.   The  :, true, false, and test builtins do not accept options
       and do not treat -- specially.  The exit, logout, break, continue, let,
       and  shift builtins accept and process arguments beginning with - with‐
       out requiring --.  Other builtins that accept  arguments  but  are  not
       specified  as accepting options interpret arguments beginning with - as
       invalid options and require -- to prevent this interpretation.
       : [arguments]
              No effect; the command does nothing beyond  expanding  arguments
              and  performing any specified redirections.  A zero exit code is
              returned.

        .  filename [arguments]
       source filename [arguments]
              Read and execute commands from filename  in  the  current  shell
              environment  and return the exit status of the last command exe‐
              cuted from filename.  If filename  does  not  contain  a  slash,
              filenames  in  PATH  are  used  to find the directory containing
              filename.  The file searched for in PATH need not be executable.
              When  bash  is  not  in  posix  mode,  the  current directory is
              searched if no file is found in PATH.  If the sourcepath  option
              to  the  shopt  builtin  command  is turned off, the PATH is not
              searched.  If any arguments are supplied, they become the  posi‐
              tional  parameters  when  filename  is  executed.  Otherwise the
              positional parameters are unchanged.  The return status  is  the
              status  of  the  last  command exited within the script (0 if no
              commands are executed), and false if filename is  not  found  or
              cannot be read.

1bash中,内置命令非常方便,其中help内置命令也是一个很有用的工具:help . - Eliah Kagan

有趣...名字似乎是dot-command,在你的情况下它将.bashrc包含到调用的shell程序中(在你的情况下,是你的bash环境)。由于你是从命令行调用它,它会更新你的环境变量,因为变量是在.bashrc中设置的。
echo "FOO=bar" > test
echo $FOO

没有结果,环境变量未设置。但是在你加载了“test”文件之后:

. test

环境变量 FOO 已设置并且
echo $FOO

导致输出结果
bar

我在这里找到以下信息here

使用文件(dot-command)进行源代码导入到脚本中,将其附加到脚本(与C程序中的#include指令具有相同效果)。最终结果等同于“source”代码行实际上存在于脚本主体中。这在多个脚本使用共享数据文件或函数库的情况下非常有用。

另请参阅question。在bash中,.source相同。


很棒,但我发现我不能执行 ". test",我需要在test前加一个点,而 ". .test" 是成功的。 - Zen
顺便问一下,你说的“script”是指什么?哪种脚本? - Zen
“script” 指的是一个调用“.” 的脚本。我会在回复中改进我的措辞。关于测试的执行:测试不应该被执行,它只是一个单行文件。 - noleti
关于 . test,你首先需要执行 chmod +x test 使其可执行。 - saiarcot895
1“test”不是被执行,而是被调用。这是有区别的。 - noleti
3这里的.表示引用来源。 - Avinash Raj