【问题标题】:xargs -I % command -option1 % -option2 % under cygwincygwin下的xargs -I % command -option1 % -option2 %
【发布时间】:2017-12-18 04:41:08
【问题描述】:

我从这个问题的答案中了解到: Making xargs work in Cygwin 该选项 xargs -I 在 Cygwin 下无法正常工作。有一些解决方法,但不幸的是它对我的情况没有帮助。

我的问题是,我怎样才能得到与以下相同的结果:

..somthing that produces multiple lines.. | xargs -I % command -option1 % -option2 %

在 Cygwin 环境下?

编辑:

为了澄清, 我想从标准输入中获取一些值并调用“命令”,将它们作为参数“%”放在两个地方。我想对“某物”产生的数据多次调用我的命令。

示例1:(我已经很久没有用cpp编程了,所以请原谅我的错误)

find -name *.cpp | cut -d. -f1 | xargs -I % gcc -o %.o -I %.h %.cpp

示例 2:

cat songs_to_process.txt | xargs -I % convert --format=mp3 --source=%.avi --output=%.mp3

【问题讨论】:

  • 您的问题不清楚。输出的每一行应该发生什么?
  • @choroba 我已经编辑了我的问题,感谢您的通知。
  • 你有什么版本的cygwin?你遇到了什么错误?
  • uname -r 返回 2.6.0(0.304/5/3),也许我应该更新到 2.9...
  • 错误信息是:“xargs: invalid option -- I”

标签: bash cygwin xargs


【解决方案1】:

你根本不需要 xargs 来完成这项工作——任何你的例子中都不需要。

find . -name '*.cpp' -print0 | while IFS= read -r -d '' filename; do
  basename=${filename%.*}
  gcc -o "${basename}.o" -I "${basename}.h" "${basename}.cpp"
done

...或:

while IFS= read -r song; do
    song=${song%$'\r'} # repair if your input file is in DOS (CRLF) format
    convert --format=mp3 --source="$song".avi --output="$song".mp3
done <songs_to_process.txt

请参阅BashFAQ #1,了解在 bash 中逐行处理输入的最佳实践。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-19
    • 2015-10-16
    • 2018-06-02
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    相关资源
    最近更新 更多