I noticed that if I type:
ls --color=auto | cat ls --color=auto > >(cat)
I don't see the same output. Therefore I assume a program has an hability to know whether its STDOUT is piped to something. The question is how does it know?
I checked the ENV vars with
env | cat but I get the same. The answer is somewhere else. I can't figure out where.
From this question I found that I can use
isatty() who provide this function? is it part of the shell or the kernel? By going further I see that this function is part of the POSIX standard.
Now I know I have two processes that can communicate in between them with several mechanism:
- Exit Code
- Environment variables
- System calls
Bash and ls are both programs. Thus they can only use the listed mechanisms to exchange information.
The real question behind this is how does
isatty() get the information from bash?