管道是否修改了单词的分隔符?

Does the pipeline modify the separator of words?

我对管道操作很困惑。例如:

# ls *.cfg
anaconda-ks.cfg  initial-setup-ks.cfg
# ls *.cfg | cat
anaconda-ks.cfg
initial-setup-ks.cfg

仅执行 ls 操作时,显示由空格 space(或制表符)分隔的项目:

anaconda-ks.cfg  initial-setup-ks.cfg

但是通过管道,space 似乎被新行替换了:

anaconda-ks.cfg
initial-setup-ks.cfg

怎么理解呢?是修改分隔符的管道吗?

man page for ls给你答案:

If standard output is a terminal, the output is in columns (sorted vertically) and control characters are output as question marks; otherwise, the output is listed one per line and control characters are output as-is.

当管道传输到另一个命令时,您的输出不是终端(即交互式登录会话)。