node.js - 等价于 sh 的 <()?

标签 node.js shell sh zsh

我有一个在我的 zsh 中运行的脚本。

cat foo.txt <(node bar.js) > out.txt

这个小脚本在使用 /bin/sh 的 node.js 模块中配置执行。问题是 sh 在 < 处失败

/bin/sh: -c: line 0: syntax error near unexpected token `('

目标是将 foo.txt 的内容和执行脚本的输出连接成一个 out.txt

我能以某种方式使用 sh 实现同样的事情吗?

最佳答案

您可以通过在 {...} 中对命令进行分组来实现与原始脚本相同的效果像这样:

{ cat foo.txt; node bar.js; } > out.txt

使用 <(...)这样你就可以cat这是尴尬和低效的。像这样使用分组更好,更便携,所以我认为这是对原始脚本的改进。

关于node.js - 等价于 sh 的 <()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22311006/

相关文章:

javascript - Angular.js : how to update one item of an array?

string - bash脚本: replace white space with "\" in string

linux - 可以将 10 个相似的函数变成一个 for 循环吗?

node.js - 如何在nodejs中反序列化avro?

javascript - Node.js - 在 Server.js 上执行 Node 命令(Express + React + Webpack)

node.js - Sequelize 查询执行循环

windows - 无法在 Windows Docker 容器中运行 cygwin

bash - 如何在非 Bash Shell 中迭代 Null 分隔结果

python - 在 Python 中逐行写入管道的正确方法

linux - 使用 bash 添加一个常数来移动文件名