The other day I found myself writing a shell script in PHP because I refuse to learn bash’s archaic syntax. I’m actually a lot happier with PHP as a shell scripting language than a web application language. However, I’ve always wanted a scripting language with the power of Mono/.NET.
So yesterday I quickly threw together cssh: C# Shell. You can’t use it as a real shell like bash, but it does allow you to write quick little C# programs that can be run like a script.
Basically the shebang (#!) tells your shell to run your script via cssh. cssh then strips out the shebang line, prepends a Class and a Method declaration, appends a return 0; as well as a couple closing brackets (}), and executes it in memory using Microsoft.CSharp namespace and Reflection.
In all it took about 60 lines of code to write. You can download a zip file with the source and a binary if you’re interested. It should compile and execute just fine under both Mono and Windows/.NET, although Windows lacks shebang script support.
While this was an interesting exercise, I’m not sure its worth pursuing. C# isn’t a scripting language, so to make it really useful you’d want to make some language modifications. I think I’m going to take a look at boo or python instead of continuing to develop cssh. Although I do love my semicolons…
Well, you can have your semis in Python if you really want them. It is syntactically (but not stylistically
) ok to end most lines with a semicolon.
C# shell…
C-sharp shell? Great!
Although my friend, when asked whether he would like to have a shell with bindings to Java, replied “System.out.println(”NO”);”… I was playing around with different shells. Zoidberg (perl), psh (perl)…
I don’t find a way to get arguments passed to the script (neither in last mono csharp shell interpreter version 2.4.2.3)
So this is a little hack to do so with your shell ^^
29c29
source[1] = “public int ExecuteScript(string[] args) {“;
47a48,50
> List Args = new List();
> Args.AddRange(args);
> Args.RemoveAt(0);
53c56
new object[]{Args.ToArray()});
Sorry my patch was killed by WordPress
there is the correct patch of Main.cs:
http://codepad.org/0gLyDD3v