Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 7 down vote accepted

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

http://www.netmite.com/android/mydroid/cupcake/kernel/fs/binfmt_script.c

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. in-ulm.de/~mascheck/various/shebang has lots of information and history. –  grawity Mar 9 '10 at 21:25
1  
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
show 1 more comment

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.

http://en.wikipedia.org/wiki/Shebang_(Unix)#As_magic_number explains how it works pretty well.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.