From: Rudolf Polzer Date: 2003-04-21T05:03:16+09:00 Subject: Re: Multi-Lingual Ruby Scripsit ille �Tim Heaney� : > Ryan Pavlik writes: > > > > The question is why this influences ruby... > > In the Perl documentation, it says > > If the #! line does not contain the word "perl", the pro- > gram named after the #! is executed instead of the Perl > interpreter. This is slightly bizarre, but it helps peo- > ple on machines that don't do #!, because they can tell a > program that their SHELL is /usr/bin/perl, and Perl will > then dispatch the program to the correct interpreter for > them. > > Perhaps Matz reasoned similarly for Ruby. But it's implemented differently. rpolzer@katsuragi tmp $ ls -l r lrwxrwxrwx 1 rpolzer users 13 2003-04-20 21:35 r -> /usr/bin/ruby rpolzer@katsuragi tmp $ cat test #!/tmp/r print "Hello\n" rpolzer@katsuragi tmp $ ruby test test:1: Can't exec /tmp/r (fatal) That took very LONG - and the reason: rpolzer@katsuragi tmp $ strace ruby test 2>&1 |grep ^exec execve("/usr/bin/ruby", ["ruby", "test"], [/* 62 vars */]) = 0 execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = 0 execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = 0 execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = 0 execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = 0 execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = 0 execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = 0 execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = 0 execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = 0 execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = 0 [...] execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = 0 execve("/tmp/r", ["/tmp/r", "test"], [/* 62 vars */]) = -1 EMFILE (Too many open files) Perl, contrary, doesn't do that with a similar setup: execve("/usr/bin/perl", ["perl", "test"], [/* 62 vars */]) = 0 execve("/tmp/p", ["/tmp/p", "test"], [/* 62 vars */]) = 0 and then happily runs the script. Probably it checks if the script interpreter names match (argv[0] and the #! line). I think it can be shown like that: rpolzer@katsuragi tmp $ perl test Can't exec /tmp/pa at test line 1. but rpolzer@katsuragi tmp $ ./p test Hello while ./p is symlinked to /usr/bin/perl. Why? #!/tmp/pa contains the substring 'p'... -- > Hatte ~1a lang $NONAMELAPTOP als Arbeitsplatz, der wurde > auch recht warm. Einmal so warm, da� [...] das Display einfror [...] Das verletzt den zweiten Hauptsatz der Thermodynamik. [Sebastian Posner und Stefan Froehlich in dasr]