1

这是我想要实现的目标。我想在该文件上运行一系列命令,例如

ls * | xargs (cat - | calculateforfile)

我想分别(cat | calculateforthisfile)在每个文件上运行。所以基本上,如何将命令列表分组,就好像它是一个函数一样?

4

2 回答 2

1

无需使用 xargs。只需使用一个循环。您也不需要使用cat. 只需使用文件重定向其输入。

for A in *; do
    calculateforfile < "$A"
done

作为单行:

for A in *; do calculateforfile < "$A"; done
于 2013-09-18T01:57:59.627 回答
0

如果您正在为此寻找xargs解决方案(例如 find 命令)

find . -name "*.txt" | xargs -I % cat %

.txt 这将包含在当前目录下找到的所有以The -Ioption is the key结尾的文件

于 2013-09-18T02:02:02.097 回答