Live data from Hacker News

Linux Bash vs. Windows PowerShell

vedipen.com

61–70 of 93 posts

Re: Linux Bash vs. Windows PowerShell

#61

The article does need a lot more fleshing out. As many have said here the thing that powershell has over bash is piping objects.

That presumes, which is always my complaint about this subject, that this is an advantage. I'd say that's what sh, ksh, and bash have over powershell (tm).

The problem with pipelines of objects is that it is inherently a more strongly typed, defined, interface. And therefore special-case. Streams of characters is as loosely typed as it gets. And for processing text files and gluing disjointed tools together, it may seem crude, but is very effective. Especially for quick text processing jobs, or automating series of commands.

The UNIX shell concept has been honed and refined over 50 years to do exactly what it does, and it does it very well. It is also extremely generic. This choice was on purpose and has stood up well to the test of time.

Powershell is somewhat a perl-for-windows-admins. A write only pile of special tools and special cases for the peculiarly baroque system interfaces of that particular OS. Neither better or worse than VBA from what I can tell, just the passing style this decade.

Re: Linux Bash vs. Windows PowerShell

#62
post #13

The real difference is: in any reasonable bash script there will be a significant amount of awk, cut, tr and other commands to munge the output of one command into the input expected by the next. In PowerShell that totally goes away.

In the past 10 years I've noticed a lot of the manipulations I used to do in "awk, cut, tr" etc are baked into bash.

Even so, there is still a lot of text manipulation that you need to do that is simply a distraction from the actual functionality of your script

Re: Linux Bash vs. Windows PowerShell

#63

Article might be more successful if it demonstrated some of the advantages of PowerShell, such as returning the output as objects instead of lines, and what you can do with them as a result. I'll admit to being in the "Bash is what I know, I'll just install WSL/Cygwin/PuTTY on my Windows workstation and be done with it" crowd. PowerShell is on my bucket list of things I need to learn at some point, or at the very lea…

> Article might be more successful if it demonstrated some of the advantages of PowerShell, such as returning the output as objects instead of lines, and what you can do with them as a result. The costs of doing this don't get enough mention though. You're essentially locking yourself into an ecosystem. It's typical in bash to have a pipeline where every program is written in a different language -- shell scripts, Py…

It would be nice if PowerShell had object serialization and deserialization functions built into the language or standard library, similar to the Common Lisp read and print functions.

This would make it possible for PowerShell to interoperate with other command line facilities.

Re: Linux Bash vs. Windows PowerShell

#64
post #54

Earlier quoted context omitted.

Thanks rasengan. I've been using PowerShell for about 5 years now. I was trying to learn Bash, but I found too limiting -- it was like going backwards. So, I started learning Python. You'll notice that the PowerShell and Python versions are very similar.

Yes, because they do much less than the shell version Here is a shell version which does the same thing as python, it is much smaller as well: https://github.com/realrasengan/autobahn/pull/8/files#diff-6...

In fairness, when I ported the Bash version to PowerShell and then Python, the Bash version was much shorter. rasengan later added a lot of functionality to the Bash version.

And the point was to demonstrate some of the functionality in a short example, not to be a line-by-line port. I find it's easier to learn a new language by looking at a short example. The rest is left as an exercise to the reader.

Re: Linux Bash vs. Windows PowerShell

#65

Article might be more successful if it demonstrated some of the advantages of PowerShell, such as returning the output as objects instead of lines, and what you can do with them as a result. I'll admit to being in the "Bash is what I know, I'll just install WSL/Cygwin/PuTTY on my Windows workstation and be done with it" crowd. PowerShell is on my bucket list of things I need to learn at some point, or at the very lea…

A very basic example of that, from my own use, is storing the result of a frequently issued large recursive directory search that always returns much the same list of files in a variable, and then using foreach to iterate over the variable multiple times to do stuff. Being a list of objects rather than an array of strings means that object properties and methods are still available within the loop bodies, the objects not having been flattened into just filenames.

PowerShell occupies the same area on Windows that REXX did on OS/2, indeed the same area that Object REXX did. Its useful properties are not that it can be made to look somewhat like POSIX shell commands. In many ways asking "What are the advantages over a POSIX shell?" is not even asking the right question. Its useful properties are rather different.

One such is that it can be used as an interpreted environment for rapidly prototyping .NET programs. I've used it to interactively do quick and dirty mixed file and SQL handling that would have required several full edit+compile+debug cycles in C# (and not just edit-and-continue).

It can speak to anything that has a .NET API. This includes Windows Forms. https://github.com/jdebp/terminal-tests/blob/master/PowerShe... is a PowerShell program that uses ECMA-48 output to Windows Terminal to draw a wriggling worm, with a Windows Forms dialogue box alongside it that can control various test parameters as it goes.

It's employable in the same sort of "glue" areas that REXX was. It is very useful in Azure/TFS build pipelines, for example. Don't think of it as a "server" thing because of this, though. It's a "glue" thing, as useful on desktop machines as on servers. It's the same improvement over writing glue as CMD scripts on Windows as REXX was over writing glue as CMD scripts on OS/2.

I haven't explored its embeddability myself, but like TCL, REXX, and others it can be used as an embedded in-process scripting language within other programs. Again, this isn't something that one directly contrasts with a POSIX shell.

Re: Linux Bash vs. Windows PowerShell

#67

Earlier quoted context omitted.

Same, unless you are on windows only, ps has no benefit. The selling point of ps is the piping of objects. Mac and linux api don't output those.

PowerShell is built on top of .Net Core, which is also cross-platform. It does pipe objects on all 3 platforms.

Not the point. No unix api does.

Re: Linux Bash vs. Windows PowerShell

#68
post #36

Earlier quoted context omitted.

I made a Bash script for HN, and while I’m the furthest thing from an expert in Bash (I’m a newb), I was impressed by a contribution made with a port of the script to Powershell[1]. You can see the same script compared in Bash, Powershell and Python! Prior to this I had never really explored PS, but it is definitely cool Shameless Plug: [1] https://github.com/realrasengan/autobahn

Thanks for posting this, it's interesting to see the same problem solved in 3 languages. I use Bash for all my scripting needs, on both Windows and Linux - I just can't get over my dislike of Powershell's verbose syntax and Pascal-Snake-Case naming! But some things are difficult or finicky in Bash; maybe I should stop putting off learning Python...

PowerShell commands are not case sensitive.

Commands use - structure, for example Get-ADUser gets an AD user. Once you learn that, it's easy to know that the equivalent command for AzureAD is Get-AzureADUser.

It did take me a while to get used to it, but it does make sense, and it makes it easier to learn/remember commands.

Re: Linux Bash vs. Windows PowerShell

#69
post #36

Earlier quoted context omitted.

Thanks for posting this, it's interesting to see the same problem solved in 3 languages. I use Bash for all my scripting needs, on both Windows and Linux - I just can't get over my dislike of Powershell's verbose syntax and Pascal-Snake-Case naming! But some things are difficult or finicky in Bash; maybe I should stop putting off learning Python...

PowerShell commands are not case sensitive. Commands use - structure, for example Get-ADUser gets an AD user. Once you learn that, it's easy to know that the equivalent command for AzureAD is Get-AzureADUser. It did take me a while to get used to it, but it does make sense, and it makes it easier to learn/remember commands.

I know about the lack of case sensitivity, but in idiomatic Powershell, it's Pascal-Kebab-Case. If I use a language, almost everyone else's code is going to be idiomatic, so I would write idiomatic code too.

Re: Linux Bash vs. Windows PowerShell

#70

Article might be more successful if it demonstrated some of the advantages of PowerShell, such as returning the output as objects instead of lines, and what you can do with them as a result. I'll admit to being in the "Bash is what I know, I'll just install WSL/Cygwin/PuTTY on my Windows workstation and be done with it" crowd. PowerShell is on my bucket list of things I need to learn at some point, or at the very lea…

> Article might be more successful if it demonstrated some of the advantages of PowerShell, such as returning the output as objects instead of lines, and what you can do with them as a result. The costs of doing this don't get enough mention though. You're essentially locking yourself into an ecosystem. It's typical in bash to have a pipeline where every program is written in a different language -- shell scripts, Py…

PWSH runs on top of the .NET runtime. So you can use any CLI language to write your code: C++, C#, VB, F#, Python, as well as PWSH.
Post reply on HN