Linux / bash,获取输入行的列表,并使用xargs在每一行上工作:

% ls -1 --color=never | xargs -I{} echo {}
a
b
c


Cygwin,采取1:

$ ls -1 --color=never | xargs -I{} echo {}
    xargs: invalid option -- I
    Usage: xargs [-0prtx] [-e[eof-str]] [-i[replace-str]] [-l[max-lines]]
           [-n max-args] [-s max-chars] [-P max-procs] [--null] [--eof[=eof-str]]
           [--replace[=replace-str]] [--max-lines[=max-lines]] [--interactive]
           [--max-chars=max-chars] [--verbose] [--exit] [--max-procs=max-procs]
           [--max-args=max-args] [--no-run-if-empty] [--version] [--help]
           [command [initial-arguments]]


Cygwin,请采取2:

$ ls -1 --color=never | xargs echo
a b c


(是的,我知道有一种ls -1 --color=never | while read X; do echo ${X}; done的通用方法,我已经测试过它也可以在Cygwin中工作,但是我正在寻找一种使xargs在Cygwin中正确工作的方法)

最佳答案

使用-nxargs参数,它实际上是您应该使用的参数,因为-I是用于为参数赋予“名称”的选项,因此您可以使它们出现在命令行的任何位置:

$ ls -1 --color=never | xargs echo
a b c
$ ls -1 --color=never | xargs  -n 1 echo
a
b
c


从联机帮助页:

   -n max-args
          Use at most max-args arguments per command line

   -I replace-str
          Replace occurrences of replace-str in the initial-arguments with names read from standard input.

关于bash - 使xargs在Cygwin中工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25562978/

10-11 06:30
查看更多