我有一个文本文件,其中每行是我想传递给nodejs脚本的参数列表。这里有一个例子文件,file.txt的:通过shell脚本将引用的参数传递给节点?
"This is the first argument" "This is the second argument"
出于演示的缘故,节点脚本是:
console.log(process.argv.slice(2));
我想运行在文本文件中的每一行此节点脚本,所以我使这个bash脚本,run.sh:
while read line; do
node script.js $line
done < file.txt
当我运行这个bash脚本,这是我得到:
$ ./run.sh
[ '"This',
'is',
'the',
'first',
'argument"',
'"This',
'is',
'the',
'second',
'argument"' ]
但是,当我只需要直接运行的节点脚本我得到预期的输出:
$ node script.js "This is the first argument" "This is the second argument"
[ 'This is the first argument',
'This is the second argument' ]
这是怎么回事?有更多的节点方式来做到这一点?
的感谢!那就是诀窍 – Rafael