Search code examples
linuxbashshellunixpipeline

Does the pipeline modify the separator of words?


I have a confusion about pipeline operation. E.g.:

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

When executing ls operation only, it displays items separated by blank space (or tab):

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

But through the pipeline, it seems the space is replaced by the new line:

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

How to understand it? Is it the pipeline that modify the separator?


Solution

  • The man page for ls gives you your answer:

    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.

    When piping to another command, your output is not a terminal (i.e. an interactive login session.)