使xargs在Cygwin中工作 [英] Making xargs work in Cygwin

查看:55
本文介绍了使xargs在Cygwin中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Linux/bash, taking the list of lines on input and using xargs to work on each line:

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

Cygwin,采取1:

Cygwin, take 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:

Cygwin, take 2:

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

(是的,我知道在读取X时有 ls -1 --color = never |的通用方法;做echo $ {X};完成,我已经测试了它在Cygwin中的工作原理同样,但我正在寻找一种方法来使 xargs 在Cygwin中正常工作)

(yes, I know there's a universal method of ls -1 --color=never | while read X; do echo ${X}; done, I have tested that it works in Cygwin too, but I'm looking for a way to make xargs work correctly in Cygwin)

推荐答案

使用 xargs -n 参数,它实际上是您应该使用的参数,例如 -I 是一个选项,用于为参数指定一个名称",以便使它们出现在命令行中的任何位置:

Use the -n argument of xargs, which is really the one you should be using, as -I is an option that serves to give the argument a 'name' so you can make them appear anywhere in the command line:

$ 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.

这篇关于使xargs在Cygwin中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆