Bash:使用点或“源”调用另一个脚本 - 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20094271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash: using dot or "source" calling another script - what is difference?
提问by setevoy
Let's take little example:
让我们举个小例子:
$ cat source.sh
#!/bin/bash
echo "I'm file source-1"
. source-2.sh
And:
和:
$ cat source-2.sh
#!/bin/bash
echo "I'm file source-2"
Now run:
现在运行:
$ ./source.sh
I'm file source-1
I'm file source-2
If I'll change call of second file in first:
如果我首先更改第二个文件的调用:
$ cat source.sh
#!/bin/bash
echo "I'm file source-1"
source source-2.sh
It will have same affect as using dot
.
它将与使用dot
.
So - what is difference it this methods? Thanks.
那么 - 这种方法有什么区别?谢谢。
采纳答案by devnull
回答by chepner
The only difference is in portability. .
is the POSIX-standard command for executing commands from a file; source
is a more-readable synonym provided by bash
and some other shells. bash
itself, however, makes no distinction between the two.
唯一的区别是便携性。.
是用于从文件执行命令的 POSIX 标准命令;source
是由bash
和其他一些 shell提供的更易读的同义词。bash
然而,它本身并没有区分这两者。