.号命令
# .
bash: .: filename argument required
.: usage: . filename [arguments]
一般在执行一个文件的时候,都会启动一个新的子shell来运行,而"."是在当前shell运行程序。这样就造成一个重要的结果,文件中的环境变量保留在当前shell中。
The . command (a.k.a. source) is like an "include" directive. It
reads the contents of a file and executes them in the current process
... just as though you had typed them at the prompt. Normally the shell
executes (external) commands in subprocesses ... regardless of whether
those are shell scripts, or Perl, Python, compiled binaries or whatever.
It's only if you source the file that the contents of the file are read and processed by your current shell/process.
Conceptually source is most similar to eval. The difference is that source takes a filename as an argument while eval processes a string (usually a value in some variable). In some ways eval
is also confusing because you can often just put a shell variable
dereference/expression where you'd put a command and the shell will
evaluate that. There are only some odd cases (deferred variable
evaluation) where the eval keyword is necessary. --by Jim Dennis
阅读(2920) | 评论(0) | 转发(0) |