24

I've always found it awkward when complex shell commands involve parsing text output with AWK. Basically we're converting structured data into text, then parsing the text again to get back at the structured data.

PowerShell is a Windows shell which avoids that problem by allowing you to pipe typed objects between shell commands instead of just text.

Are there any Unix shells which are object-based instead of text-based, like PowerShell?

7 Answers 7

25

No, it is the other way around. There is no spoon^H^H^Hstructured data. There is only text.

A big part of the Unix philosophy is based on the idea of outputting text and accepting text as input. You might want to consider reading "The Art of Unix Programming", which has a nice explanation about this.

Don't get me wrong: I understand your point and I know what you are trying to get at. There are things like the interactive interpreters of Ruby and Python, which can be used as a shell, but they are not as friendly for basic tasks as Bash is. Try and change directory, for example.

Also, using objects in a shell is not all-that. If only your shell supports this, on Unix, you would be at a loss. All the standard Unix text manipulation tools would have to be altered, like grep, awk, sed, etc.

I think there has been an attempt to create something like this a few years back, but I can't remember the name and I haven't heard about it in a long time. It's probably not going to take off.

8
  • 2
    Interestingly, replacing text streams (or actually, byte streams) by data object streams would not go against the general principles formulated in the book. It even seems to play better with the "rule of representation". It's just that unix has chosen text streams as the interface between programs.
    – Wim Coenen
    Aug 12, 2010 at 13:32
  • 1
    But by 'data object' do you mean an actual Python / Ruby / C++ object or something like a C struct?
    – wzzrd
    Aug 12, 2010 at 14:04
  • 3
    +1 "Do not try to bend the spoon, that's impossible. Instead only try to realize the truth... there is no spoon." It's not so much text-as-an-interface, but streams of data as an interface. Objects are nice for programming, but sometimes they become a little tiny prison to put your mind into... Aug 12, 2010 at 17:16
  • 2
    zsh > bash. My opinion but really if you haven't tried zsh you should Aug 12, 2010 at 22:19
  • 3
    @WimCoenen, shipping around "structured data" means everybody and aunt Tillie have to agree what the "structure" is. Even stuff like ls(1). Completely useless.
    – vonbrand
    Mar 20, 2013 at 23:32
10

There's actually a project called Pash that aims to implement PowerShell (on top of Mono), but it seems to have stalled.

2
7

PowerShell became open-source in 2016. Since then it's been getting more and more multi-platform. The source code is available on GitHub and so are install packages for a number UNIX-like systems.

4

There is a project, whose goal share similarity with PowerShell: Hotwire. It combines regular sh with python scripting and window/graphical environment. You could give it a look.

It's based around object-oriented pipeline that you can extend with your own objects by wrapping existing programs or using Python libraries.

1
  • 1
    That's the project I was trying to remember the name off! Last commit in trunk: two years ago...
    – wzzrd
    Aug 12, 2010 at 14:03
1

I would think you could accomplish most of that by writing a bunch of interpreted (or compiled) scripts, then invoking them within the interpreter's shell, which will return or preserve your objects and so on if you want.

You can do this in at least Ruby, Perl, Python, Haskell (e.g., GHCi), JavaScript (e.g., node.js), Matlab, and certainly other languages...

1
  • The pipe being objects mean you can do lazy evaluation etc. So if you are passing a set of file objects down a pipe.. maybe you care about the name, or the modified date, but maybe the content. What data do you pass in JSON? Answer: it depends. If the consumer of the pipe pulls data, it can request the right data. Problem solved. Aug 31, 2016 at 4:02
1

Another thought three years later: It's possible to represent an object with a text stream using either XML or JSON. I prefer JSON (simpler), and, indeed there are projects out there to give the classic *NIX utilities JSON support. For example: https://github.com/step-/JSON.awk

One issue with using an object-type model for classic *NIX programs like AWK is that they really do not have OO support. For example, while AWK does have associative arrays, the arrays are not multi-dimensional (each element in an AWK array has to be a number or a string; an array is not allowed to be an array object in AWK).

1
  • Clojure offers edn which allows all sorts of typed data to be serialized/deserialized while JSON is limited.
    – Mario
    Dec 19, 2014 at 16:40
0

Nacre.sh is a shell designed to manipulate objects (JSON) instead of text. For instance, ls returns an array of path, stat an object containing information about a file, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.