有哪些基于对象的 shell?

发布于 2024-09-10 07:51:11 字数 360 浏览 6 评论 0原文

我打算写一个面向对象的shell(基于Python)。我已经有很多想法了。但在实现它之前,我想通过一些现有的 shell 来激发我的灵感。

我所说的面向对象的基本含义是:

  • 参数不仅仅是字符串数组,而是对象数组。
  • 返回值也是一个对象。
  • 不仅有 stdin、stdout 和 stderr,还有任意数量的命名流,这些命名流可以是某些类型(不仅仅是字节流)。

我读到 Windows PowerShell 有点类似(基于 .Net)。虽然我正在寻找一些现有的 Linux/MacOSX shell。

当然还有 IPython,但它并不是真正的 Unix shell,即管道传输相当复杂。

I am planning to write an object-oriented shell (based on Python). I have many ideas already. But before I am going to implement it, I want to inspire me by some existing shell.

What I basically mean by object-oriented:

  • Parameters are not just an array of strings but an array of objects.
  • The return value is also an object.
  • There is not just stdin, stdout and stderr but any possible number of named streams which can be of certain types (not just a stream of bytes).

I have read that the Windows PowerShell is somewhat like that (based on .Net). Though I am searching for some existing Linux/MacOSX shells.

Of course there is also IPython but it is not really intended as a Unix shell, i.e. piping stuff around is quite complicated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深居我梦 2024-09-17 07:51:11

Microsoft 的 PowerShell(核心)默认安装在现代版本的 Windows 上,也可以安装在 Linux 上。这是一个非常好的工具,预热时间有点长,但是一旦完成就非常有用。

我真正喜欢它的功能是过滤:

 ls | Where-Object { $_.size -eq 0 }

谁可以以紧凑形式重写

 ls | ? { $_.size -Eq 0 }

和转换(后面跟着它的紧凑形式):

 ls | Foreach-Object { $_.name -replace "\folderName","daba" }
 ls | % { $_.name -replace "\folderName","daba" }

您还可以在 shell 语言中轻松创建管道过滤器,这是一个非常简洁的功能。

Function concat()
{
    Begin { $rez = ""; }
    Process { $rez = $rez + $_ }
    End { $rez }
}


ls | % { $_.name } | concat

最后一个表达式列出所有文件,提取文件名并将它们连接在一个字符串中(可能是一些命令行开关来执行此操作,但我不记得名称了)。

PowerShell 的另一个重要部分是内省,您可以从命令行查询对象属性/方法:

ls | Get-Member

对于使用新对象确实有用,它比 python 中的 dir() 更具描述性
[1]:http://www.microsoft.com/windowsserver2003/技术/管理/powershell/default.mspx

Microsoft's PowerShell (Core), installed by default on modern versions of Windows, can be installed on Linux too. It's a really good tool, a bit long to warm-up, but once it's done it's really useful.

The features I really love in it is the filtering :

 ls | Where-Object { $_.size -eq 0 }

who can be rewritten in the compact form

 ls | ? { $_.size -Eq 0 }

and the transformation (followed by it's compact form ):

 ls | Foreach-Object { $_.name -replace "\folderName","daba" }
 ls | % { $_.name -replace "\folderName","daba" }

you can also easily create pipe filter within the shell language, which is a pretty neat feature.

Function concat()
{
    Begin { $rez = ""; }
    Process { $rez = $rez + $_ }
    End { $rez }
}


ls | % { $_.name } | concat

The last expression list all files, extract the filename and concatenate them in a single string (it might be some commandlet to do that, but I don't remember the name).

Another important part of the PowerShell, is the introspection, you can query your object property/methods from the command line :

ls | Get-Member

Really useful to play with new objects, it's a bit more descriptive than dir()from python
[1]: http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx

韶华倾负 2024-09-17 07:51:11

也许您可能想看看 Pash

它是适用于其他平台的 PowerShell 的开源实现。出于教育目的和灵感,它可能会有用。不幸的是,据我所知,这个有前途的项目尚未开发。

Perhaps you may want to take a look at Pash.

It is an open source implementation of the PowerShell for other platforms. For educational purposes and inspiration it might be useful. Unfortunately, as far as I can see, this promising project is not being developed.

Spring初心 2024-09-17 07:51:11

根据 维基百科上的 shell 比较列表,唯一可以做到这一点的现有 shell 是 MS PowerShell和 IPython(如果算作命令 shell),带有用于管道的 IPipe 扩展

如果只算真正的跨平台解决方案,则无法使用MS PowerShell
这已经过时了,PowerShell 现在是跨平台的。

还有它的 Pash 端口(感谢 Roman 注意到它),尽管它不完整,因此不是确实有用。

According to the shell comparison list on Wikipedia, the only existing shells which can do that are MS PowerShell and IPython (if that counts as a command shell) with the IPipe extension for piping.

If you only count real cross platform solutions, MS PowerShell cannot be used.
This is outdated, PowerShell is cross-platform now.

There is also the Pash port of it (thanks Roman to notice it), though it is incomplete and thus not really useable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文