如何将标准输出通过管道传输到另一个程序?

spi*_*ock 6 shell pipe git stdout

我正在尝试为我的代码设置一个 linter,我只想对当前分支中已更改的 coffeescript 文件进行 lint。因此,我使用git以下命令生成文件列表:

git diff --name-only develop | grep coffee$
Run Code Online (Sandbox Code Playgroud)

这给了我一个我想要处理的文件的漂亮列表,但我不记得如何将它传递给 linting 程序来实际完成工作。基本上我想要类似于find's 的东西-exec

find . -name \*.coffee -exec ./node_modules/.bin/coffeelint '{}' \;
Run Code Online (Sandbox Code Playgroud)

谢谢!

spi*_*ock 1

xargs是我正在寻找的 unix 实用程序。从手册页:

The xargs utility reads space, tab, newline and end-of-file delimited strings from the standard input and executes utility with the strings as arguments.

Any arguments specified on the command line are given to utility upon each invocation, followed by some number of the arguments read from the standard input
 of xargs.  The utility is repeatedly executed until standard input is exhausted.
Run Code Online (Sandbox Code Playgroud)

所以,我原来的问题的解决方案是:

git diff --diff-filter=M --name-only develop | grep coffee$ | xargs ./node_modules/.bin/coffeelint
Run Code Online (Sandbox Code Playgroud)