what object-based shells are there?

2019-05-23 01:27发布

问题:

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.

回答1:

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.



回答2:

Microsoft's Powershell. Installed by default on Windows 7 & Server 2008, can be installed on XP & Vista. It's a really good tool, a bit long to warm-up, but once it's done it's really usefull.

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 cmdlet to do that but I don't remember the name).

Another important part of the powershell, is the introspection, you can query your object proprety/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



回答3:

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. There is the Pash port of it (thanks Roman to notice it), though it is incomplete and thus not really useable.

So, to answer my question: There is no such thing yet.