【问题标题】:How can I concatenate pipeline string into file [duplicate]如何将管道字符串连接到文件中[重复]
【发布时间】:2019-11-05 09:11:54
【问题描述】:

我如何将带有前缀 HELLO 的 node -pe "require('./package.json').version" 放入文件中?

node -pe "require('./package.json').version" | "HELLO" + $res > file.txt 不工作。

我想使用单行命令(不是完整的多行 bash 脚本)

简单演示

echo "world" | "HELLO" + $res > file.txt

文件中的预期输出 - HELLO world

【问题讨论】:

标签: linux bash


【解决方案1】:
  • 您的 $res 变量未设置
  • 管道用于将程序/脚本的输出重定向到另一个程序的输入;您的行中缺少第二个程序

解决方案可能是这样的(未测试):

echo "HELLO" + $(node -pe "require('./package.json').version") > file.txt

$(command substitution) 捕获命令的输出。

【讨论】:

    猜你喜欢
    • 2014-10-21
    • 2019-03-03
    • 2019-01-05
    • 2013-02-26
    • 2013-02-07
    • 1970-01-01
    • 2013-09-14
    • 2014-08-05
    • 2020-07-17
    相关资源
    最近更新 更多