【问题标题】:How can i use pipe with argument in Linux/Unix-like我如何在类 Linux/Unix 中使用带参数的管道
【发布时间】:2021-08-02 20:53:44
【问题描述】:

我想做这样的事情:

$ ( foo1.sh $1 | foo2.sh | bar.sh |) arg

有时管道比写函数快,但我可以在管道之间传递parameters/args
现在:我正在通过xbps 搜索包firefox,但我在下面收到此错误:

$ xbps-query -Rs $1 | fzf firefox   

xbps-query: option requires an argument -- 's'
unknown option: firefox

【问题讨论】:

  • 为什么不直接xbps-query -Rs firefox | fzf?
  • 因为我使用复杂的管道(sed,awk...),我不想每次都回到中间来更改参数
  • 这是一个编程网站。如果您询问交互式使用,Unix & Linux 是一个更好的地方。
  • 是的,我想是的

标签: linux bash pipe fzf


【解决方案1】:

管道没有参数。相反,编写一个带参数并运行所需管道的脚本或函数:

foo() {
  xbps-query -Rs "$1" | fzf
}

然后您可以使用foo firefox 运行它

【讨论】:

  • 我不想要函数,但我搜索类似`xbps-query -Rs {} | fzf {firefox}`,
  • 你可以bash -c 'xbps-query -Rs "$1" | fzf' _ firefox 但我不知道你为什么会这样做
  • 是的,它工作正常^_^ @that-other-guy
猜你喜欢
  • 2011-08-26
  • 2014-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-11
  • 1970-01-01
相关资源
最近更新 更多