小编Raf*_*ael的帖子

通过shell脚本将引用的参数传递给节点?

我有一个文本文件,其中每一行都是我想传递给nodejs脚本的参数列表.这是一个示例文件file.txt:

"This is the first argument" "This is the second argument"
Run Code Online (Sandbox Code Playgroud)

为了演示,节点脚本很简单:

console.log(process.argv.slice(2));
Run Code Online (Sandbox Code Playgroud)

我想为文本文件中的每一行运行此节点脚本,所以我创建了这个bash脚本run.sh:

while read line; do
    node script.js $line
done < file.txt
Run Code Online (Sandbox Code Playgroud)

当我运行这个bash脚本时,这就是我得到的:

$ ./run.sh 
[ '"This',
  'is',
  'the',
  'first',
  'argument"',
  '"This',
  'is',
  'the',
  'second',
  'argument"' ]
Run Code Online (Sandbox Code Playgroud)

但是,当我直接运行节点脚本时,我得到了预期的输出:

$ node script.js "This is the first argument" "This is the second argument"
[ 'This is the first argument',
  'This is the second argument' ]
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?是否有更多节点方法可以做到这一点?

bash node.js

5
推荐指数
1
解决办法
1624
查看次数

检测.csv文件是否实际上是.xls(Excel)文件

我想检测用户是否意外上传了标记为.csv的Excel文件.xls文件是否有标准的二进制占用空间可以实现这一目标?

csv xls binary-data

5
推荐指数
1
解决办法
617
查看次数

标签 统计

bash ×1

binary-data ×1

csv ×1

node.js ×1

xls ×1