[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

shebang (was Re: systemd - some more considerations)



On Fri, 4 Apr 2014, Chow Loong Jin wrote:

> Are you sure about this?

Yes.

> Some references would be helpful. I can't seem to find anything on this through

Sure. I’ve patched mksh to use “#?” ipv “#!” as shebang, to
simulate a kernel not supporting the shebang:

Index: exec.c
===================================================================
RCS file: /cvs/src/bin/mksh/exec.c,v
retrieving revision 1.129
diff -u -p -u -p -r1.129 exec.c
--- exec.c	11 Jan 2014 16:26:27 -0000	1.129
+++ exec.c	4 Apr 2014 09:34:58 -0000
@@ -893,7 +893,7 @@ scriptexec(struct op *tp, const char **a
 		/* restore begin of shebang position (buf+0 or buf+3) */
 		cp = (unsigned char *)(buf + fd);
 		/* bail out if read error (above) or no shebang */
-		if ((cp[0] != '#') || (cp[1] != '!'))
+		if ((cp[0] != '#') || (cp[1] != '?'))
 			goto noshebang;
 
 		cp += 2;

(Some comment on the side: “buf+0 or buf+3” is because mksh additionally
strips an UTF-8 BOM before the shebang. This is beyond standard.)

Then I run this:

tglase@tglase:~ $ cat x
#?/usr/bin/python
import sys
print sys.version
tglase@tglase:~ $ ls -l x
-rwxr-xr-x 1 tglase tglase 47 Apr  4 12:54 x
tglase@tglase:~ $ ./x
import.im6: unable to grab mouse ': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9047.
sys.version
tglase@tglase:~ $ b/mksh
tglase@tglase:~ $ ./x
2.7.6 (default, Mar 22 2014, 17:40:27) 
[GCC 4.8.2]

(This is Debian sid/i386 (still waiting for x32, that’s why i386).)

> some cursory googling.

Try duckduckgoïng instead ☻ or searching POSIX, or something.

Also, “man mksh” look for EXECSHELL (which is the interpreter the
shell uses if the script doesn’t even have a shebang).

bye,
//mirabilos
-- 
Sometimes they [people] care too much: pretty printers [and syntax highligh-
ting, d.A.] mechanically produce pretty output that accentuates irrelevant
detail in the program, which is as sensible as putting all the prepositions
in English text in bold font.	-- Rob Pike in "Notes on Programming in C"


Reply to: