Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what object-based shells are there?

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.

like image 491
Albert Avatar asked Jun 26 '26 07:06

Albert


1 Answers

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

like image 67
Raoul Supercopter Avatar answered Jun 28 '26 00:06

Raoul Supercopter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!