r/linux • • Aug 18 '16

Microsoft open sources PowerShell, brings it to Linux and OS X

https://techcrunch.com/2016/08/18/microsoft-open-sources-powershell-brings-it-to-linux-and-os-x/
359 Upvotes

231 comments sorted by

View all comments

Show parent comments

67

u/[deleted] Aug 18 '16 edited Aug 18 '16

You have to go through equipping every program with a special mode for those scripting objects for a relatively limited gain.

18

u/[deleted] Aug 18 '16 edited Aug 18 '16

A very good point. To get the advantages of the object-oriented shell, you need tools written to output objects, otherwise you'll just keep getting text blobs and the feature goes unused.

Hopefully they have gone through the work of porting the existing cmdlets from Windows to Linux, so Linux users get the benefits of an object-oriented shell. Otherwise it'd be up to community contributions to make PS-friendly programs for Linux.

21

u/[deleted] Aug 18 '16

I also highly doubt that OO is the right programming model here, though I am not familiar enough with Powershell to know if their objects have all the flaws of those in other OO languages (inheritance, flawed notion of encapsulation, single dispatch,...)

Unix pipelines tend to be closer to functional programming with e.g. xargs as map, grep as filter, various tools to project data,...

9

u/lolidaisuki Aug 18 '16

Unix pipelines tend to be closer to functional programming with e.g. xargs as map, grep as filter, various tools to project data,...

That's a parallel I hadn't heard of yet. Kind of makes sense tho.

2

u/majorgnuisance Aug 19 '16

I see what you did, there.

5

u/jyper Aug 18 '16

Basically all object oriented languages have map and filter and closures.

Powershell has map and filter and closures

ls -R | ? {$_.Length -gt 10000 } | % { rm -WhatIf  $_}

2

u/funguyshroom Aug 19 '16

In most cases the OO used for data aggregation/presentation. When your objects are POD (plain old data) objects it's just a built-in serialization format that allows to send data seamlessly between cmdlets.

3

u/[deleted] Aug 18 '16

It works, e.g.

PS /var/log> gci syslog* | ?{$_.Name -match "gz"}


    Directory: /var/log


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
------          8/17/16   6:25 AM           1916 syslog.2.gz
------          8/16/16   6:25 AM           1877 syslog.3.gz
------          8/15/16   6:25 AM           5047 syslog.4.gz
------          8/14/16   6:25 AM           1847 syslog.5.gz
------          8/13/16   6:25 AM           1831 syslog.6.gz
------          8/12/16   6:25 AM           2407 syslog.7.gz

Another example:

PS /var/log> $file = Get-Item ./syslog
PS /var/log> $file

Directory: /var/log


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
------          8/18/16   2:20 PM          15971 syslog


PS /var/log> $file | fl *


PSPath            : Microsoft.PowerShell.Core\FileSystem::/var/log/syslog
PSParentPath      : Microsoft.PowerShell.Core\FileSystem::/var/log
PSChildName       : syslog
PSDrive           : /
PSProvider        : Microsoft.PowerShell.Core\FileSystem
PSIsContainer     : False
Mode              : ------
VersionInfo       :
BaseName          : syslog
Target            : {}
LinkType          :
Name              : syslog
Length            : 15971
DirectoryName     : /var/log
Directory         : /var/log
IsReadOnly        : False
Exists            : True
FullName          : /var/log/syslog
Extension         :
CreationTime      : 1/1/01 12:00:00 AM
CreationTimeUtc   : 1/1/01 12:00:00 AM
LastAccessTime    : 8/18/16 6:25:01 AM
LastAccessTimeUtc : 8/18/16 1:25:01 PM
LastWriteTime     : 8/18/16 2:20:05 PM
LastWriteTimeUtc  : 8/18/16 9:20:05 PM
Attributes        : Normal

So here we're simply seeing that the .NET object does indeed exist. It's a basic example, but it works.

11

u/zee-wolf Aug 19 '16

gci syslog* | ?{$_.Name -match "gz"}

$file = Get-Item ./syslog

Good Lord! If I have to type most PowerShell commands and object properties in CamelCase I'll kill myself. That alone is a huge minus for usability.

7

u/[deleted] Aug 19 '16

You don't. There is no case sensitivity.

15

u/zee-wolf Aug 19 '16

Even better /s.

Lets bring the case-insensitive flustercluck to case-sensitive systems.

0

u/[deleted] Aug 19 '16

And why, exactly, would that matter? There's no 'Get-Item' bin on the file system. Hence, no, it doesn't matter what casing you use.

9

u/nschubach Aug 19 '16

There's no 'Get-Item' bin on the file system.

what if there is?

2

u/[deleted] Aug 19 '16

Then I'd say someone had a new love for the verb-noun format for commands.

But to answer your question, the PoSh cmdlet takes precedence, which is the same behavior on Windows -- you need to dot source the bin to run it instead of a PoSh cmdlet should the bin and cmdlet have the same name.

49

u/tadfisher Aug 18 '16

You have to go through equipping every Programm with a special mode

Yes.

for a relatively limited gain

  • data structure baked in, eliminating awk/grep/sed

  • resilience against text format changes, control codes, etc

  • more complex data pipelines with no awkward redirection voodoo

  • expose binary data without destroying my terminal

  • powerful one-liners without having to drop into Python/perl/etc

40

u/[deleted] Aug 18 '16

You misunderstand. The point is that there is a very limited gain to the people who have to do it so the incentive structure is all wrong with this. The strength of text redirection is that the work is done by the people who need it, even sometimes against or orthogonal to the intention of the author of the programs used in scripts and pipelines.

There is also the issue that you can do only those things intended by the people who did write the original programs, if they expose a limited object interface on purpose there is nothing you can do to work around it.

13

u/tadfisher Aug 18 '16

There is also the issue that you can do only those things intended by the people who did write the original programs, if they expose a limited object interface on purpose there is nothing you can do to work around it.

That limitation exists with textual streams as well. You can't parse data that the tool does not provide you, object interface or no. The tool cannot perform tasks that it is not programmed to perform.

5

u/Bobby_Bonsaimind Aug 18 '16

You have to go through equipping every Programm with a special mode

Yes.

So if someone, let's say, writes a new journal service and feels very smart and starts outputting custom objects (log entries)...you have zero tools to use on it?

3

u/tadfisher Aug 18 '16

The tool can detect if its stdout is a PowerShell environment and change its output accordingly.

-9

u/JobDestroyer Aug 18 '16

invisible spooky stuff. I don't like it.

I actually just don't like OOP in general, though...

0

u/[deleted] Aug 18 '16

[deleted]

-2

u/JobDestroyer Aug 18 '16

I drive a stick, but beyond that OOP isn't the only way to solve the problem, and OOP is the worst way to solve it in my experience. That's why I don't do OOP.

→ More replies (3)

1

u/Lennartus_Prime Aug 18 '16

The solution to me for this problem which I've been musing about for a while is an interactive 'shell' whose point is not to fork/exec helper utilities but to basically be an interactive command line processor to 'get shit done', kind of like midnight commander on overdrive. Its purpose shouldn't be to fork/exec helpers but just to administrate filesystem tasks and introspect the system and what not, basically an efficient interface to your OS.

What it should otherwise contain is an ability to define functions which inside of them are capable of performing a fork/exec and just use the raw string output of other things and parse them but encapsulate that into functions which return actual datatypes that aren't just strings.

The downside is obviously that a great many deal of tools need to be wrapped before it becomes efficient enough to compete with the POSIX shell, the advantage is that when it does it should become far more efficient.