Trying to write a shell script with someone else (for the first time for me), thought to myself:
What would I do on Windows as an equivalent?
And I came up with a Javascript solution. Now thinking further I thought: Why not try to write a script that will run within the Windows Scripting Host, the .NET CLR and a browser?
The funny thing is: You can actually write such a script. The only thing (with such a simple script) that differs is IO. But thanks to Javascript´s try - catch (Which I hadn´t known of until three weeks ago, and I have done a lot of JS), that is not a problem either.
You can take a look at the script
here. It´s nothing spectacular, takes a date, adds X days an returns the new date, all without the Date object (I did the script as a pre-version of the shell script, so I kept all the fancy stuff out).
The most interesting part is this:
try{
alert(targetyear+" "+targetmonth+" "+targetday+"
"+elapsed);
} catch (e) {
try{
print(targetyear+" "+targetmonth+" "+targetday+" "+elapsed);
}catch(e1) {
try{
//Sh = new ActiveXObject("WScript.Shell");
WScript.Echo(targetyear+" "+targetmonth+" "+targetday+" "+elapsed);
} catch (e2) {
}
}
}
I tried some more, and found out that especially JScript.NET is mighty as hell. But there are some drawbacks: Even a script that should only parse arguments given won´t run in all three environments because you need to use the
import statement in JScript.NET to access
System.Environment. God what I hate this design decission in .NET, that a FQN won´t suffice.