gpt4 book ai didi

linux - 如何将两次查找的结果用于单个 xargs

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:47:31 26 4
gpt4 key购买 nike

我在 Ubuntu 14.04 上。假设一个文件夹中有未知数量的可执行文件。

ATest, BTest, CTest

我想使用与其名称相关的自定义命令行参数来执行每个可执行文件。例如,

valgrind --xml=yes --xml-file=ATest.log ./ATest 
valgrind --xml=yes --xml-file=BTest.log ./BTest
valgrind --xml=yes --xml-file=CTest.log ./CTest

我可以通过以下方式获取可执行文件

find . -executable -type f

我可以通过以下方式获取自定义命令行参数

find . -executable -type f -printf '%f\n'

我可以

find . -executable -type f | xargs -n 1 valgrind --xml=yes --xml-file=Test.log 

但不幸的是日志文件的名称不是自定义的。我尝试将其组合如下,但没有成功

find . -executable -type f -printf '%f\n' && find . -executable -type f | xargs -n 2 valgrind --xml=yes --xml-file={}.log

为单个 xargs 组合两个查找结果的正确方法是什么?

最佳答案

您可以使用:

find . -executable -type f -printf '%f\n' |
xargs -I {} valgrind --xml=yes --xml-file={}.log ./{}

或者这个xargs:

find . -name '*Test' -executable -type f -print0 |
xargs -0 -I {} bash -c 'valgrind --xml=yes --xml-file="${1##*/}.log" "$1"' - {}

这将执行这 3 个命令:

valgrind --xml=yes --xml-file=ATest.log ./ATest
valgrind --xml=yes --xml-file=BTest.log ./BTest
valgrind --xml=yes --xml-file=CTest.log ./CTest

关于linux - 如何将两次查找的结果用于单个 xargs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35417856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com