Unix - " xargs" - 输出“在中间” (不是最后!) [英] Unix - "xargs" - output "in the middle" (not at the end!)
问题描述
ls | xargs echo
它与(假设我有 someFile
和
someDir /
在工作目录中):
echo someFile someDir
so xargs
取其输入并将它放在下一个命令的最后(这里是echo的结尾)。
但有时我想要 xargs
将其输入放置在下一个命令的中间中。
例如:
find。 -type f -name* .cpp-print | xargs g ++ -o outputFile
所以如果我在当前目录中有 a .cpp
, b.cpp
, c.cpp
输出将与命令:
g ++ -o outputFile a.cpp b.cpp c.cpp
但我想要这样:
g ++ a.cpp b.cpp c.cpp -o outputFile
有没有办法这样做吗?
PS:在某些情况下我需要它,因为例如:
i586-mingw32msvc-g ++ -o outputFile`pkg-config --cflags --libs gtkmm-2.4` a.cpp b.cpp c.cpp
不起作用,但这个工作正常:
i586- mingw32msvc-g ++ a.cpp b.cpp c.cpp -o outputFile`pkg-config --cflags --libs gtkmm-2.4`
$ b $如果您的xargs版本不包含 -I
功能,则替代方案i s写一个包含要执行的命令的小shell脚本:
#!/ bin / sh
exec i586-mingw32msvc-g ++$ @-o outputFile ...
然后使用xargs来运行:
find。 -type f -name* .cpp-print | xargs my_gcc_script
example use of xargs
application in Unix can be something like this:
ls | xargs echo
which is the same as (let's say I have someFile
and someDir/
in the working directory):
echo someFile someDir
so xargs
take its input and place it at the end of the next command (here at the end of echo).
But sometimes I want xargs
to place its input somewhere in the middle of next command.
For example:
find . -type f -name "*.cpp" -print | xargs g++ -o outputFile
so if I had in the current directory files a.cpp
, b.cpp
, c.cpp
the output would be the same as with the command:
g++ -o outputFile a.cpp b.cpp c.cpp
but I want to have something like this:
g++ a.cpp b.cpp c.cpp -o outputFile
Is there a way to do it?
P.S.: I need it in some cases, because e.g.:
i586-mingw32msvc-g++ -o outputFile `pkg-config --cflags --libs gtkmm-2.4` a.cpp b.cpp c.cpp
doesn't work but this one works fine:
i586-mingw32msvc-g++ a.cpp b.cpp c.cpp -o outputFile `pkg-config --cflags --libs gtkmm-2.4`
If your version of xargs doesn't include the -I
feature, an alternative is to write a little shell script containing the command you want to execute:
#!/bin/sh
exec i586-mingw32msvc-g++ "$@" -o outputFile...
Then use xargs to run that:
find . -type f -name "*.cpp" -print | xargs my_gcc_script
这篇关于Unix - " xargs" - 输出“在中间” (不是最后!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!