我知道这一点source
并.
做同样的事情,如果标题中的其他命令对不是同样的事情,我会感到惊讶(因为我将 bash 作为我的 shell 运行,$SHELL [script]
并且bash [script]
是等效的,对吧?? )。
那么这三种执行脚本的方法有什么区别呢?我问是因为我刚刚了解到采购脚本与执行它并不完全相同。在某种程度上,我从运行我的“实验”和阅读手册页中发现并不明显。
通过在我编写的极其简单的脚本上盲目地调用这些函数,我找不到其他哪些细微差别?在阅读了上面链接的答案之后,我可以强烈地猜测我的问题的答案将是一个非常简单的解释,但在某种程度上,我自己几乎永远不会完全发现。
这是我做的“实验”:
$. 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."