I have a c# source file. Is there any way to put something like #!/usr/bin/env mono, so it will be compiled and then run as executable:
For python for example, i’ll do like this:
#!/usr/bin/env python
In fact, what I want is to run the script without calling “mono the.exe”, after compiling. I want something like “./the.exe”.
EDIT: I just noticed you want to do this for a single source file—for a single source file. This is almost supported by the
csharpREPL that ships with Mono. However, the REPL spits out a syntax error because it doesn’t understand the shebang line and sees it as a preprocessor definition. If I misunderstood and you were talking about a compiled assembly, the below text still applies. /EDITYou can’t use shebangs, because .exe files produced by Mono are PE executables, just like on Windows. They contain CIL, not a script.
What you can do though is produce a small shell script that runs
mono your.exeand use that, or you can use the Linux kernel’s binfmts support, as outlined here.