I have a c# source file. Is there any way to put something like #!/usr/bin/env mono, so it 开发者_StackOverflow中文版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 csharp
REPL 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. /EDIT
You 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.exe
and use that, or you can use the Linux kernel's binfmts support, as outlined here.
I think you may be able to use update-binfmts
to register mono
as the interpreter for (compiled) mono programs.
Try update-binfmts --display
and see if the output includes something like:
cli (enabled):
package = mono-common
type = magic
offset = 0
magic = MZ
mask =
interpreter = /usr/bin/cli
detector = /usr/lib/cli/binfmt-detector-cli
精彩评论