我使用变量中的 tail 来回显文件夹中多个文件的内容。
VAR="$(tail -n +1 DIR/*/file)"
这将输出所有文件内容以及所需的文件名,例如
==> /folder/subdir1/file <==
some content from file in subdir 1
==> /folder/subdir3/file <==
some content from file in subdir 3
==> /folder/subdir2/file <==
some content from file in subdir 2
很好,但是当我还想按子目录排序时
VAR="$(tail -n +1 DIR/*/file | sort)"
它显示为
some content from file in subdir 1
some content from file in subdir 2
some content from file in subdir 3
==> /folder/subdir1/file <==
==> /folder/subdir2/file <==
==> /folder/subdir3/file <==
我怎样才能实现它按排序显示但看起来像第一个例子中没有排序命令一样?