Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们可以将参数传递给 Nodejs 中的 .sh 文件吗,我正在尝试生成一个.sh文件,并希望在生成时传递一些参数,
.sh
var command = spawn(__dirname + "/import.sh", { var1: "abc" });
在上面的命令中,我试图生成文件 import.sh 并尝试传递参数,我不知道这是否是正确的方法 以及如何检索import.sh文件中的变量值?
import.sh
最后我得到了答案:
var env = Object.create(process.env); env.var1 = "abc"; var command = spawn(__dirname + "/import.sh", { env: env });
并import.sh简单地检索它:
if [ ${var1} == "abc" ] then // your code goes here fi
而已 :)