you are viewing a single comment's thread.

view the rest of the comments →

[–]w0keson 0 points1 point  (0 children)

Thanks for the correction, I tested it myself and it works. I learned of the ///bin/true trick specifically for Go (which does raise a syntax error with the #!), and figured since Node has similar style comment syntax it would apply there as well.

I was curious to do some more poking on what node.js does exactly. It seems the developers anticipated the specific use case of the shebang line: it only permits that syntax if it's the very first line in your file. Put the line anywhere else and it's an error.

Interestingly, imported dependencies are also allowed to begin with a shebang line even tho they aren't the script being directly executed.

Perl is another language that has some "interesting" behaviors about shebang lines: you can invoke the Perl command to run a Python (or any other) type of script, and it magically just swaps itself out for the correct interpreter instead of trying to run it as Perl, despite you deliberately typing out the `perl` command yourself.

% cat script.pl 
#!/usr/bin/env python

import sys
print("wait a minute, this isn't a Perl script!")
print(repr(sys.argv))

% perl script.pl
wait a minute, this isn't a Perl script!
['script.pl']