是否有类似于针对Linux的Microsoft Powershell(基于.NET框架构建的面向对象的shell)(可能基于Java,GObject或其自己的对象类型/没有)?
编辑:特别是如果类似于bash或powershell或cmd等语法(='''标准''shell语法)
答案 0 :(得分:10)
的Python。不开玩笑。
脚本语言是脚本语言,Python是一个非常好的,很多人都觉得非常平易近人。
答案 1 :(得分:8)
即使这个问题已经很久了,我认为值得一提的是,在2016年8月,微软开发了Powershell开源和跨平台。安装说明在github上。
答案 2 :(得分:4)
好的,我相信你已经知道了,但有人不得不说出来。
Perl是最古老,最受欢迎的。
如果你喜欢对象,你可能会喜欢Ruby。它有一个精心设计的对象系统,受到Smalltalk的启发。
Python有这种很酷的块结构 - 缩进语法。
Unix是高级脚本工具的金矿......
答案 3 :(得分:1)
答案 4 :(得分:1)
NodeJS可以做到这一点,实际上它是下载中包含的示例之一。以交互方式使用它,或者(可能更有用)在JavaScript中编写shell脚本。
例如:
#!/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);
});
...但这只是一个高级接口,可以为你缓冲所有输出,等等。如果你愿意的话,你可以获得更多的肮脏和肮脏。
NodeJS将异步性视为正常的事务状态,因此如果你想要一个“传统的”shell脚本,你可能会发现它不是一个好的匹配,因为它没有(截至本文写作,据我所知)提供exec
的同步版本。因此,一系列特殊的串行语句成为回调练习:
exec('first_command', function(error) {
if (error != null) {
exec('second_command', function(error) {
if (error != null) {
// ....
}
});
}
});
...但是,当然,您可以创建一个函数来处理这个问题,然后执行(比方说)一系列顺序语句来执行(然后通过Node的模块系统将其作为模块安装)。例如:
#!/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();
}
});
}
}
}
答案 5 :(得分:0)
你应该重新考虑为什么你认为你需要一个面向对象的shell。也就是说,如果你设置了奇怪的贝壳,那么zoid就不会出错。与我在这里看到的许多其他建议不同,它确实是一个shell。另一方面,如果你不知道或不喜欢Perl,你可能会不高兴。
答案 6 :(得分:0)
jq不是一个面向对象的shell,但它提供了面向对象shell可能具有的一些好处;我将它与shell脚本一起用于此类任务。