sách gpt4 ăn đã đi

linux - : ". [script]" or "source [script]", "bash [script] or $SHELL [script]"和 "./[script]"或 "[script]"有什么区别?

In lại 作者:IT王子 更新时间:2023-10-29 00:43:18 30 4
mua khóa gpt4 giày nike

Tôi biết nguồn. 做同样的事情,如果标题中的其他命令对不一样,我会感到惊讶事情(因为我正在运行 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."

câu trả lời hay nhất

。 scriptsource script 在当前环境中执行 kịch bản 的内容,即不创建子 shell。从好的方面来说,这允许 kịch bản 影响当前环境,例如更改环境变量或更改当前工作目录。不利的一面是,这允许 kịch bản 影响当前环境,这是一个潜在的安全隐患。

bash script Sẽkịch bản 传递给đập mạnh 解释器来执行。 kịch bản 本身给出的任何 shebang 都会被忽略。 (“Shebang”指的是 kịch bản 的第一行,例如可以读作 #!/bin/bash hoặc #!/usr/bin/perl hoặc #!/usr/bin/awk,指定要使用的解释器。)

$SHELL script Sẽ kịch bản 传递给您当前的 shell 解释器 以执行。这可能是也可能不是 đập mạnh。 (环境变量 SHELL 包含当前 shell 解释器的名称。如果运行 bash,$SHELL 将评估为 /bin/bash,具有上一段中详述的效果。)

./script 执行文件 kịch bản 在当前工作目录中的内容。如果没有这样的文件,则会生成错误。 $PATH 的内容对发生的事情没有影响。

kịch bản hiện hữu $PATH 中列出的目录中查找文件 kịch bản ,这可能会也可能不会包含当前工作目录。执行此目录列表中的第一个 kịch bản,它可能是也可能不是您当前工作目录中的脚本。

关于linux - : ". [script]" or "source [script]", "bash [script] or $SHELL [script]"和 "./[script]"或 "[script]"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45761508/

30 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress