如何打印命令的结果以及结果的计数?

How to print result of a command as well as the count of results?

我必须打印所有包含作为控制台参数给出的查询的文件,下一行就是这样做的

find . "$path" -type f -name "*$key*" -print

然而我也想获得总文件数,但是这样做:

find . "$path" -type f -name "*$key*" -print | wc -l

会给我这些文件的计数,但不会给我这些文件的名称,这不是我们想要的结果。如何用一根衬垫修复它(如果可能)?

使用命令 tee duplicating the output of the pipe and Bash‘s Process Substitution 作为文件的占位符,将复制的流提供给 wc:

$ seq 11 15 | tee >(wc -l)
11
12
13
14
15
5