|
|
Posted Jul 05, 2008 at 9:11:34 PM
Subject: Help with the #!/bin/whatever line in scripts
I'm writing a lexer for a custom scripting language, and I want it to parse the first line of the scripts the same way the shell/kernel does. I'm wondering if anyone has the EXACT specification of what is legal/illegal in that area. Or information on where it's parsed.
I am specifically talking about lines like this:
#!/bin/bash
bash code here
Or, you can specify any executable in the first line, with parameters, for example:
#!/home/smlefo/test -a -b
this is a custom script
Which will execute the 'test' program, with the parameters -a and -b, along with the filename.
I'm curious as to where this first line is parsed (is it part of the ELF specification? or is interpreted by the shell, or somewhere in the kernel?).
Also, during my investigation of what is legal, I found out that the absolute path can't have any spaces... so for example:
#!/home/smlefo/test directory/test -a -b
blah
Will obviously execute the file /home/smlefo/test, with the parameters directory/test, -a, and -b. But what if I want it to interpret "test directory" as an actual directory? I tried:
#!/home/smlefo/test\ directory/test -a -b
blah
But that failed with the error:
bash: ./ts: /home/smlefo/test\: bad interpreter: No such file or directory
So... if anyone has any hints as to where I can find the exact specification of this, that would be very helpful. Thank you.
~Sean
|