My mind was blown when I accidentally ran a bash script using perl and it... worked. Experimenting further, it seems perl reads a script's shebang and dispatches to the correct interpreter:
$ cat /tmp/ohhai.sh
#!/bin/bash
echo ohhai bash
$ perl /tmp/ohhai.sh
ohhai bash
$ cat /tmp/ohhai.py
#!/usr/bin/python2
print 'ohhai python'
$ perl /tmp/ohhai.py
ohhai python
$ cat /tmp/ohhai.groovy
#!/usr/bin/groovy
println 'ohhai groovy'
$ perl /tmp/ohhai.groovy
ohhai groovy
um... wut?
To make sure I'm not crazy, I tried doing this with other interpreters and confirmed this is just a perl-ism:
$ python /tmp/ohhai.sh
File "/tmp/ohhai.sh", line 2
echo ohhai bash
^
SyntaxError: invalid syntax
$ ruby /tmp/ohhai.sh
ruby: no Ruby script found in input (LoadError)
$ bash /tmp/ohhai.py
/tmp/ohhai.py: line 2: print: command not found
Is this documented somewhere? Is it a new thing/old thing? ... Why?
"Swiss-Army chainsaw" indeed.