How does a "hashbang" line actually work?
I'm familiar with the fact that when you execute a script, the program that the kernel actually launches is the interpreter program named on the #! line, and the script is then passed to that program as an argument. But what program actually carries out the necessary analysis? Does the kernel say, "Oops! This is text, not machine code; I need to look for an interpreter." Or does the shell do something different when it forks off the process? That seems more likely, but not all scripts are launched from a shell.
AntiX has a rather neat graphical Control Centre for administrative tasks which is written in Python. It uses pygtk to create a nice dialog window with tabs and big square buttons. When you press a button, a shell script is launched to carry out the specified task. Here fluxbox must be forking the python script which then forks the shell script.
All the code is in /usr/local/bin (which is where AntiX stores stuff that doesn't come from Debian) so you can inspect it and see how it works on the surface. But it made me wonder how a thing like that works internally.
|