Zen*_*Zen 11 command-line bash scripts alias bashrc
我看到一篇关于修复你的别名的帖子.bashrc
。
他说在你把你的别名放进去后.bashrc
,你需要使用:
. ~/.bashrc
Run Code Online (Sandbox Code Playgroud)
我不太明白第一个点(' . ') 在这里做什么。它的功能是什么,叫什么名字?
c0r*_*0rp 20
如果您想在 bash 中检查某些内容,请使用 type
和man
。
在您的情况下,您想知道什么是 .
$ type .
. is a shell builtin
Run Code Online (Sandbox Code Playgroud)
shell 内置意味着. 在里面bash shell
。您可以在bash
手册页中找到有关 shell 内置函数的信息。有一大段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.
Run Code Online (Sandbox Code Playgroud)
有趣...名称似乎是dot-command
,在您的情况下,它将 .bashrc 包含到调用 shell 程序中(在您的情况下,您的 bash 环境)。当您从命令行调用它时,它会更新您的环境变量,因为变量是在 .bashrc 中设置的。
echo "FOO=bar" > test
echo $FOO
Run Code Online (Sandbox Code Playgroud)
没有结果,环境变量未设置。但是在您获取“测试”文件之后:
. test
Run Code Online (Sandbox Code Playgroud)
设置了环境变量 FOO 并且
echo $FOO
Run Code Online (Sandbox Code Playgroud)
导致输出
bar
Run Code Online (Sandbox Code Playgroud)
我在这里找到了以下信息:
获取文件(点命令)将代码导入脚本,附加到脚本(与 C 程序中的 #include 指令效果相同)。最终结果与“来源”代码行实际存在于脚本主体中一样。这在多个脚本使用公共数据文件或函数库的情况下很有用。
另外,请参阅此问题。在 bash 中,.
与source
.
归档时间: |
|
查看次数: |
3014 次 |
最近记录: |