I am working on displaying output like ls command (just ls, no options). And I have a working program using the system calls. But I experienced a strange behavior while testing as shown below.
$ ls
a b c
$ ls > somefile
$ cat somefile
a
b
c
so, as you see the output is written one file per file, NO ADDITIONAL SWITCHES WERE GIVEN TO LS. You can test it out. So from above I infer, ls command has some built-in logic to display it one per line if written to a file via redirection.
To add to the puzzle, I believe it's the shell that interprets the redirection.
So I am confused I would like to kown what exactly is making the output one per line if redirected to a file? Any hint?