how to define script interpreter with shebang

bash, linux, sml, unix

Solution

With a wrapper that removes the first line and calls the real interpreter with the remainder of the file. It could look like this:

#!/bin/sh

# set your "real" interpreter here, or use cat for debugging
REALINTERP="cat"

tail -n +2 $1 | $REALINTERP

Other than that: In some cases ignoring the error message about that first line could be an option.

Last resort: code support for the comment char of your interpreter into the kernel.

Problem

It is clear that one can use the ``` #!/usr/bin/perl ``` shebang notation in the very first line of a script to define the interpreter. However, this presupposes an interpreter that ignores hashmark-starting lines as comments. How can one use an interpreter that does not have this feature?

Original source

Related problems