News for hackers. Stuff that matters.
Re:Shell Style Guide by NiveaGeForce on Tuesday May 15, 2018 @09:34AM (#17073777)
And on Windows there is something better than Bash, called PowerShell.
Re:Shell Style Guide by chrisfinazzo on Tuesday May 15, 2018 @09:58AM (#17073933)
Not to put too fine a point on it, but that's nonsense.

Historically, PowerShell was supposed to be a replacement for cmd.exe and roughly equivalent to bash, yet suitable for the Windows environment. They tried early on to port some of the UNIX & Linux tools to Windows and it didn't fly, so this is what we're left with.

Although parts of Powershell are open source now, I suspect the mere existence of WSL means that Microsoft understands it has more to gain from compatibility with the rest of the world (Bash is nigh-everywhere) than imposing their particular philosophy on people.

(See also, Apple's decision to adopt UNIX underpinnings)

I'm prepared to be wrong if PowerShell actually gets used outside of Windows, but I wouldn't bet on it.

Re:Shell Style Guide by jve on Tuesday May 15, 2018 @10:49AM (#17074308)
> Historically, PowerShell was supposed to be a replacement for cmd.exe and roughly equivalent to bash

What? PowerShell has radically different ideology. Plus it is super consistent (helps discover commands), extensible and works with objects rather plain strings, use .NET functions or call custom .dll functions...

> They tried early on to port some of the UNIX & Linux tools to Windows and it didn't fly

Actually they just use aliases to map well-known unix commands to powershell counterparts. It is not expected to have command switches work like that etc. Just a convenience for folks used to rm, ls, tee, wget, whatever. Maybe bad decision because of confusion, maybe a good one because helps people get started with PowerShell.

For me as a Windows admin, PowerShell is one of the best things within Windows Ecosystem.

Re:Shell Style Guide by chrisfinazzo on Tuesday May 15, 2018 @11:35AM (#17074729)
There is an episode of the "To Be Continuous" podcast with Jeff Snover (PS's inventor) that gets into this a bit more. Because of the difference in philosophy, a straight port to Windows didn't work well.

Basically, text files (UNIX) v structured data from API's (Windows), thus PowerShell was born.

https://www.heavybit.com/library/podcasts/to-be-continuous/e...

Re:Shell Style Guide by AnIdiotOnTheNet on Tuesday May 15, 2018 @12:35PM (#17075219)
Powershell's philosophy is the same as the one behind core-utils: Simple tools you can chain together to do complex tasks. Only it was made with 30 years of hindsight, so it actually does it much better.
Re:Shell Style Guide by falsedan on Tuesday May 15, 2018 @10:51AM (#17074328)
Powershell on Windows is better than bash on Windows.
Re:Shell Style Guide by NiveaGeForce on Tuesday May 15, 2018 @10:32AM (#17074158)
> Not to put too fine a point on it, but that's nonsense.

In PowerShell you pass structured data around instead of globs of text, which is much more maintainable. Using Bash on Windows is like going backwards, and it's sad that most developers don't even realize it.

> Historically, PowerShell was supposed to be a replacement for cmd.exe and roughly equivalent to bash, yet suitable for the Windows environment. They tried early on to port some of the UNIX & Linux tools to Windows and it didn't fly, so this is what we're left with.

Nonsense, Powershell is a fundamental improvement. It's not a "this is what's we're left with" situation.

> Although parts of Powershell are open source now, I suspect the mere existence of WSL means that Microsoft understands it has more to gain from compatibility with the rest of the world (Bash is nigh-everywhere) than imposing their particular philosophy on people.

Yeah, let's just drag everything down to the lowest common denominator.

> (See also, Apple's decision to adopt UNIX underpinnings)

Which is sad, since it could have been so much more. The Unix way of doing things, isn't the be all and all.

https://www.youtube.com/watch?v=rmsIZUuBoQs

https://news.ycombinator.com/item?id=16813796

Re:Shell Style Guide by gerrard00 on Tuesday May 15, 2018 @10:55AM (#17074365)
I used Powershell extensively before I ever had experience with a linux or unix shell. I still have more experience with Powershell than bash or zsh, but I can't imaging going back. I'm already much more capable in a *nix shell.

There are advantages to having a pipe based on structured data, but that also means you have to know what structure to expect at ever step of the way and whether or not other tools can work with that structure. There are also tons of little quirks about Powershell; enough so that I eventually just started writing most stuff in C# and then just using the Powershell scripts as glue.

Passing text means that every single one of the thousands and thousands of unix cli tools that accept stdio will work in your pipeline.

I think this industry needs to get away from the terrible/horrible, absolute thinking. Most tools have positive and negative

Re:Shell Style Guide by protomyth on Tuesday May 15, 2018 @12:49PM (#17075343)
Passing text means that every single one of the thousands and thousands of unix cli tools that accept stdio will work in your pipeline.

It also means every one of those thousands and thousands of Unix clip tools needs to have a parser to turn that text into some sort of structure to operate on.

Re:Shell Style Guide by gerrard00 on Tuesday May 15, 2018 @05:26PM (#17078001)
Which allows them to determine exactly the best way to do that for their purposes. I just run the command and it magically works.

It'll be a long time before the Powershell ecosystem has a fraction of tools that are compatible with it's .NET object pipeline.

Re:Shell Style Guide by protomyth on Wednesday May 16, 2018 @12:24PM (#17083661)
Which allows them to determine exactly the best way to do that for their purposes. I just run the command and it magically works.

Up until someone changes the text output of the program and it all goes bad. Never mind the maintenance headaches that basically get solved by people moving their command lines into databases where typing happens.

It'll be a long time before the Powershell ecosystem has a fraction of tools that are compatible with it's .NET object pipeline.

That's more a function of age and developers than the typing itself.

Re:Shell Style Guide by nailer on Tuesday May 15, 2018 @11:15AM (#17074545)
Sad to see this downvoted.

As a 20 year bash veteran: powershell is the first OS default shell that outputs structured data, and looking at objects and selecting the properties you want is a massive improvement than combining bash with sed/grep/awk to scrape text.

Someone bizarrely responds that cmd still exists on Windows for compatibility purposes (though even Win+X starts powershell now) doesn't change this at all.

The README for my powershell profile (which is written from a *nix PoV) has a little more info comparing the two: https://github.com/mikemaccana/powershell-profile

Re:Shell Style Guide by tbyehl on Tuesday May 15, 2018 @01:30PM (#17075759)
I'm always amused by these PowerShell threads on HN.

How is it that objects are an accepted thing for basically every programming environment in modern use, yet somehow controversial when it comes to the shell?

The prayer-based text parsing toolchain sucks. It has always sucked, regardless of platform. We put up with it because it was all that we had.

Jeffrey Snover came up with something better and thanks to PS Core we'll be able to use it everywhere!

Re:Shell Style Guide by nailer on Tuesday May 15, 2018 @02:13PM (#17076231)
Yeah - most people would agree that GraphQL is a better way to access data than, say headless Chrome via Puppeteer. Many folk here prefer TeX over Word because the former encourages seperating content from presentation. But when it comes to the shell, suddenly everyone hates the idea.
Re:Shell Style Guide by dragonwriter on Tuesday May 15, 2018 @05:38PM (#17078086)
> How is it that objects are an accepted thing for basically every programming environment in modern use,

They aren't accepted for basically every programming environmental nment in modern use; peak OOP-all-the-things is well in the past, and it's no longer the one paradigm to rule them all, irrespective of use case.

Re:Shell Style Guide by nailer on Tuesday May 15, 2018 @05:50PM (#17078188)
Whether you have methods or functions, you still have hashmaps - bash you scrape values, pwsh you select keys. Pipelines can be considered quite functional too.
Re:Shell Style Guide by chrisfinazzo on Tuesday May 15, 2018 @11:12AM (#17074507)
> Nonsense, Powershell is a fundamental improvement. It's not a "this is what's we're left with" situation.

It would be, if cmd.exe was long dead, PowerShell had stolen the good parts and continued on its way, but we're not there yet. Cmd.exe still exists on Win 10 and let's not even get into the fact that 64 bit only versions of Windows are not yet everywhere. Sure, Microsoft's ecosystem is larger and more complex, but at some point Win32 becomes a liability and unnecessary baggage.

> Which is sad, since it could have been so much more. The Unix way of doing things, isn't the be all and all.

Cultural compatibility matters - See C & C++. How else do you expect to get users and developers on board if you can't show them how your system is better in a few key ways, but isn't a giant leap from what they're currently using?

Tl;dr Change is scary, try to make it less so.

Re:Shell Style Guide by Already__Taken on Tuesday May 15, 2018 @09:36AM (#17073784)
Which actually supports linux with PS 6.0+
Re:Shell Style Guide by dijit on Tuesday May 15, 2018 @09:48AM (#17073875)
Unless you want secure strings.. then it complains about "Crypt32.dll" not being available.
Re:Shell Style Guide by mauvehaus on Tuesday May 15, 2018 @10:00AM (#17073951)
Or want to pipe data without PowerShell mangling it[0]

PowerShell is materially worse than bash for a great many purposes because of this design choice alone.

[0] https://brianreiter.org/2010/01/29/powershells-object-pipeli...

Re:Shell Style Guide by MattSteelblade on Wednesday May 16, 2018 @01:50PM (#17084655)
The particular example this user complains about is piping binary data to file. It makes use of the Out-File cmdlet which is making (by default) Windows based assumptions as to how to encode this content. They would have been better served by using cURL's native -O parameter. To say that the pipe corrupts it is another thing entirely.
Re:Shell Style Guide by NiveaGeForce on Tuesday May 15, 2018 @09:40AM (#17073821)
Indeed.
Re:Shell Style Guide by stinos on Tuesday May 15, 2018 @10:53AM (#17074347)
I'm a huge PS fan and like to stay as far away as possible from Bash but still, I wouldn't call it better than Bash. At least not always and everywhere. More like different. Both come with a list of advantages and disadvantages. And once you learnt one, the list of disadvantages of the other probably seems too big to even start with it, at least that's what it is now for me.
Re:Shell Style Guide by ladzoppelin on Tuesday May 15, 2018 @10:26AM (#17074114)
Its too verbose for me and I would rather use Python or Bash. WSL is amazing for these things.
Re:Shell Style Guide by AnIdiotOnTheNet on Tuesday May 15, 2018 @12:40PM (#17075262)
It has aliases. Both built in and user definable. In fact, there are default aliases that match many of the utilities you're used to.

You might know that if you'd spent more than 30 seconds with it before shouting "it's not bash!".