这是我想要实现的目标。我想在该文件上运行一系列命令,例如
ls * | xargs (cat - | calculateforfile)
我想分别(cat | calculateforthisfile)
在每个文件上运行。所以基本上,如何将命令列表分组,就好像它是一个函数一样?
无需使用 xargs。只需使用一个循环。您也不需要使用cat
. 只需使用文件重定向其输入。
for A in *; do
calculateforfile < "$A"
done
作为单行:
for A in *; do calculateforfile < "$A"; done
如果您正在为此寻找xargs
解决方案(例如 find 命令)
find . -name "*.txt" | xargs -I % cat %
.txt
这将包含在当前目录下找到的所有以The -I
option is the key结尾的文件