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…
Pingback: Viraptor's dev-log