I thought that if I redirected the output of ls to a file, the exact same sequence of characters that would otherwise have been sent to the console would get written to that file.
To test that, I create 3 files and then list them
$ touch a b c
$ ls
a b c
I now run ls again, this time redirecting to a file which I cat
$ ls > out
$ cat out
a
b
c
out
Unexpectedly, there is an 0A linefeed character between each filename in out
$ xxd out
00000000: 610a 620a 630a 6f75 740a a.b.c.out.
Piping the output of ls to xxd
$ ls | xxd
00000000: 610a 620a 630a 6f75 740a a.b.c.out.
the linefeeds are still present.
How did the 0A bytes get there? Does ls behave differently if it's being redirected or maybe the shell ignores linefeeds in certain circumstances?
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal