I have a really small question. Let's take this command as an example cat < file.txt
.
When the shell sees the <, it redirects stdin (0 file descriptor) by forking a new process and only changing stdin to that file for that specific process environment (since it's not a builtin).
Nevertheless when we have a builtin command, the shell doesn't fork a new process, but just changes stdin to the specified file in the whole terminal environment (don't know if it's for the whole terminal environment but since the shell doesn't fork a new process I don't see how it can be done just for the program (the builtin)) and changes it back to e.g /dev/pts/0 (the normal stdin) when the program is finished
But here is where it gets fuzzy for me. When running two builtin commands of which one is in the background and both have their stdout or stdin redirected to two different files, this would mean that they'd both change the stdin (or stdout) to their own files but that means that one of the programs would use the stdin of the other program since they can't have both the stdin redirected at the same time because they aren't forked.
This is only the case though if what I mentioned above is true that stdin gets changed for the entire terminal environment and not only for the program in case of a builtin, because of not being forked
If I'm not clear, it's really hard to explain but I'll try to formulate it another way: with builtin commands, the shell doesn't fork new processes, and if one is run in the bg and one in the fg, both of which have redirected stdin or stdin to different files, how can they both at the same time have different stdins since the shell for built-in programs changes stdin in the entire terminal until the program has finished executing?