xargs -I % command -option1 % -option2 % cygwin下
xargs -I % command -option1 % -option2 % under cygwin
我从这个问题下的答案中了解到:
Making xargs work in Cygwin
该选项 xargs -I 在 Cygwin 下无法正常工作。有一些解决方法,但不幸的是,它对我的情况没有帮助。
我的问题是,我怎样才能得到与以下相同的结果:
..somthing that produces multiple lines.. | xargs -I % command -option1 % -option2 %
在Cygwin环境下?
编辑:
澄清一下,
我想从 stdin 获取一些值并调用 "command",将它们作为参数“%”放入两个位置。我想对 "something".
生成的数据多次调用我的命令
示例 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
您根本不需要 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
有关在 bash 中逐行处理输入的最佳实践的介绍,请参阅 BashFAQ #1。
我从这个问题下的答案中了解到: Making xargs work in Cygwin 该选项 xargs -I 在 Cygwin 下无法正常工作。有一些解决方法,但不幸的是,它对我的情况没有帮助。
我的问题是,我怎样才能得到与以下相同的结果:
..somthing that produces multiple lines.. | xargs -I % command -option1 % -option2 %
在Cygwin环境下?
编辑:
澄清一下, 我想从 stdin 获取一些值并调用 "command",将它们作为参数“%”放入两个位置。我想对 "something".
生成的数据多次调用我的命令示例 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
您根本不需要 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
有关在 bash 中逐行处理输入的最佳实践的介绍,请参阅 BashFAQ #1。