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…

This entry was posted in GNU/Linux, Mono/.Net, Open Source, PHP, Technology. Bookmark the permalink.
  • http://www.dowski.com Christian Wyglendowski

    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.

  • Pingback: Viraptor's dev-log()

  • Marsu

    I don’t find a way to get arguments passed to the script (neither in last mono csharp shell interpreter version

    So this is a little hack to do so with your shell ^^

    source[1] = “public int ExecuteScript(string[] args) {“;
    > List Args = new List();
    > Args.AddRange(args);
    > Args.RemoveAt(0);
    new object[]{Args.ToArray()});

  • Marsu

    Sorry my patch was killed by WordPress

    there is the correct patch of Main.cs: