Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Many scripts in different languages have a #!/bin/bash header with a path to interpreter, so they can be executed without explicit call to interpreter from command line.

But what exactly reads this line and run the interpreter, is it shell or kernel?

share|improve this question
up vote 7 down vote accepted

At least in Linux,the kernel has this functionality: fs/binfmt_script.c specifically.

I imagine, however, that some shells may bypass this, and check the first line for an interpreter line rather than just calling exec and letting the kernel figure it out.

share|improve this answer
O.K. I think I miss understood question. – Maciek Sawicki Mar 9 '10 at 2:19
OK, after reading justin answerer I think my whole concept understanding was wrong – Maciek Sawicki Mar 9 '10 at 2:27
Now, I think It would be hard to bypass this. – Maciek Sawicki Mar 9 '10 at 2:28
It used to be the shell. has lots of information and history. – grawity Mar 9 '10 at 21:25
Actually, it wasn't Android specific source code, it was the Linux kernel source code as hosted on an Android site. I didn't want to provide a URL for a tarball of the kernel that would need to be untarred to get at the file. However, linking to that site turned out to not be a very good idea for a different, reason, it no longer seems to be up... At any rate, googling Linux binfmt_script.c will find other copies for anyone interested – bdk Mar 9 '10 at 22:28

The kernel reads it. It uses the #! to detect that the file is a script and not a binary, and execs the command that follows. explains how it works pretty well.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .