I remember being surprised by this and then realising, "wait, of course it's in the kernel -- that's so much nicer from a usability and sanity standpoint".
- The shell finds opens up the file you want to execute
- It gets the first line of the file
- It figures out what program to execute
- It calls fork()
- In the new process, it executes the program (using exec()) and passes the file as the input to the program.