Is there anything similar to Microsoft Powershell (an object-oriented shell built on the .NET framework) for Linux (possibly built on Java, GObject, or its own object type/nothing)?
edit: especially if similar to bash or powershell or cmd etc. syntax (=''standard'' shell syntax)
Python. No joking.
Scripting languages are scripting languages, and Python is a particularly nice one that many people find very approachable.
Even though this question is pretty old, I think its worth mentioning that in August 2016 Microsoft made Powershell open-source and cross platform. Instructions for installation are on github.
https://github.com/PowerShell/PowerShell
Perl, Python, and Ruby
Ok, I'm sure you already know that, but someone had to say it.
Perl is the oldest and most popular.
If you like objects, you will probably love Ruby. It has an elaborate object system inspired by Smalltalk.
Python has this cool block-structure-by-indent syntax.
Unix is a gold mine of advanced scripting tools...
NodeJS can do that, in fact it's one of the samples included in the download. Use it interactively, or (probably more usefully) write shell scripts in JavaScript.
For example:
#!/usr/local/bin/node
var sys = require('sys'),
exec = require('child_process').exec;
// Run `ls`:
exec('ls -lh /usr', function(error, output, erroutput) {
sys.print('output: ' + output);
sys.print('erroutput: ' + erroutput);
});
...but that's just the high-level interface that buffers all the output for you, etc. You can get a lot more down and dirty than that if you like.
NodeJS takes asynchronicity as the normal state of affairs, and so if you want a "traditional" shell script, you may find it's not a good match as it doesn't (as of this writing, as far as I know) offer a synchronous version of exec
. So an ad hoc series of serial statements becomes an exercise in callbacks:
exec('first_command', function(error) {
if (error != null) {
exec('second_command', function(error) {
if (error != null) {
// ....
}
});
}
});
...but of course, you can create a function that handles that for you and takes (say) an array of sequential statements to execute (and then install it as a module via Node's module sysstem). So for instance:
#!/usr/local/bin/node
var sys = require('sys'),
exec = require('child_process').exec;
execSeries([
'ls -ld /usr',
'foobar',
'ls -ld /etc'
], {echo: true}, function(results) {
sys.print("Done\n");
});
// ===> This would be in a module, not in the script itself <===
function execSeries(series, options, callback) {
var index = 0,
results = [];
// Make 'options' optional
if (!callback && typeof options === "function") {
callback = options;
options = undefined;
}
// Default options
options = options || {};
// Go
callNext();
function callNext() {
if (index >= series.length) {
// Done
callback(results);
}
else {
// Call the next one
exec(series[index++], function(error, stdout, stderr) {
// Record result
results.push({error: error, stdout: stdout, stderr: stderr});
// Echo?
if (options.echo) {
if (error == null) {
sys.print(stdout);
}
else {
sys.print("Error: " + error + "\n");
}
}
// Stop on error?
if (options.breakOnError && error != null) {
// Yes, and there was an error; stop
callback(results);
}
else {
// No, continue
callNext();
}
});
}
}
}
You should rethink why it is you think you need an object-oriented shell. That said, if you're set trying weird shells you can't go wrong with zoid. Unlike many of the other suggestions I see here it really is a shell. On the other hand, if you don't know or don't like Perl you probably won't be happy.
jq is not quite an object-oriented shell, but it provides some of the benefits which object-oriented shells may have; I use it a lot, together with shell scripts, for such tasks.