The #! line has two programs that "interpret" it:
| [reply] [d/l] |
To the shell. [...] At least on unixish systems, there is always a shell involved in this process
The #! line, also called shebang, tells nothing to any shell. It's the kernel who interprets it. When the first two bytes of an executable file are #!, the kernel runs the command that follows them, with the parameters specified, and feeds it the whole file on its standard input:
$ cat > a
#!/usr/bin/tail -n2
1
2
3
4
5
6
7
^D
$ chmod +x a
$ ./a
6
7
$ strace ./a 2>&1 | grep -c sh
0
| [reply] [d/l] |
I'm trying to figure out where you get the idea that the contents are passed to tail's stdin. It's not. The full path to the file (as given by the shell - full path if searched via PATH, relative path if PATH not used) is passed in.
Compare the output of "strace ./a" and "strace /usr/bin/tail -n2 < a". The former has a call to "open" and all reading is done from filehandle 3. The latter doesn't call open, and all reading is done from filehandle 0.
| [reply] [d/l] [select] |
| [reply] |