cssh: C# Shell

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…

2 Responses to “cssh: C# Shell”

  1. Christian Wyglendowski Says:

    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.

  2. Viraptor's dev-log Says:

    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)…

Leave a Reply