【发布时间】:2018-01-27 10:14:59
【问题描述】:
我知道 source 和 . 做同样的事情,如果标题中的其他命令对不是同样的事情,我会感到惊讶(因为我正在运行 bash 作为我的shell,$SHELL [script] 和 bash [script] 是等价的,对吧??)。
那么这三种执行脚本的方法有什么区别呢?我之所以问,是因为我刚刚了解到采购脚本是NOT the exact same 作为执行它。在运行我的“实验”和阅读手册页时我没有发现明显的方式。
通过在我编写的极其简单的脚本上盲目调用这些函数,我找不到其他哪些细微差别?阅读上面链接的答案后,我可以强烈猜测我的问题的答案将是一个非常简单的解释,但我自己几乎永远不会完全发现。
这是我做的“实验”:
$. myScript.sh
"This is the output to my script. I'd like to think it's original."
$source myScript.sh
"This is the output to my script. I'd like to think it's original."
$bash myScript.sh
"This is the output to my script. I'd like to think it's original."
$$SHELL myScript.sh
"This is the output to my script. I'd like to think it's original."
$./myScript.sh
"This is the output to my script. I'd like to think it's original."
$myScript.sh
"This is the output to my script. I'd like to think it's original."
【问题讨论】:
标签: linux bash shell dot-source