我在 中看到了一篇关于修复别名的帖子.bashrc
。
他说在你输入别名后.bashrc
,你需要使用:
. ~/.bashrc
我不太明白这里第一个点(' . ')的作用。它的作用是什么,叫什么?
答案1
如果您想在 bash 中检查某些内容,请使用 type
和man
。
就你的情况来说,你想知道是什么。
$ type .
. is a shell builtin
shell 内置命令意味着。在里面bash shell
。您可以在bash
手册页中找到有关 shell 内置命令的信息。其中有一大部分Shell 内建命令
$ 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.
答案2
有趣... 名称似乎是dot-command
,在您的情况下,它将 .bashrc 包含到调用 shell 程序中(在您的情况下,是您的 bash 环境)。当您从命令行调用它时,它会更新您的环境变量,因为变量是在 .bashrc 中设置的。
echo "FOO=bar" > test
echo $FOO
没有结果,环境变量未设置。但是在你获取“测试”文件之后:
. test
环境变量 FOO 已设置,并且
echo $FOO
输出结果为
bar
我找到了以下信息这里:
获取文件(点命令)将代码导入脚本,并附加到脚本中(与 C 程序中的 #include 指令效果相同)。最终结果与“获取”的代码行实际存在于脚本主体中相同。当多个脚本使用公共数据文件或函数库时,这很有用。
另外,看看这个问题. 在 bash 中,.
与 相同source
。