Live data from Hacker News

PowerShell vs. Unix shells

stackoverflow.com

1–10 of 84 posts

Re: PowerShell vs. Unix shells

#2
When writing shell script, try to develop an awareness of how much you use sed, awk, tr, `` and so on to munge the output from one command into the format or value you want for the next. If it's a lot then something like PowerShell (or equiv on Unix) may be what you're after.

Re: PowerShell vs. Unix shells

#3
How much can you do with powershell regards system configuration?

For example, could you put a Windows Server with PS behind SSH and login and config everything that way without having to touch the GUI?

Re: PowerShell vs. Unix shells

#4
I used powershell pretty comfortably for years when managing Windows boxes, it does the job superbly. It's a bit weaker as a general-use scripting language (a la Python/Ruby), but I believe it never promised to be that kind of tool. It's just always tempting to use it as a REPL for when whipping out a throwaway C# project in VS is too much of a hassle. It works as one, I'm just not a huge fan of its syntax.

Re: PowerShell vs. Unix shells

#5
PowerShell compared to Cygwin bash, in my experience:

* Powershell is more capable than bash, straight up.

* bash is easier to use; writing ad-hoc pipes etc. in PowerShell has never seemed pleasant to me, the commands are verbose and the contractions non-obvious; getting help is tedious, and options are often very long.

* Object orientation works well when you're dealing with meaningful objects. But often you just want to deal with a singular list of items, and it can make things more awkward. It's a bit like the OO - relational dichotomy.

* Interaction between PowerShell and Unix utilities is very clunky, because by default PowerShell will include column headers and formatting characters as part of the output. Something else that's unpleasant: PowerShell doesn't have a simple mode that can work well inside a terminal. I mean, just running PowerShell inside Cygwin mintty results in a copyright notice and an apparantly hung program. That's because it's using ReadConsole rather than ReadFile for I/O, but ReadConsole only works in Windows' horrible console windows. You can work around it with 'powershell -', but then you don't get a prompt. Similarly, running a PowerShell script requires echoing a return character to the PowerShell process to get it to exit! Literally: "echo | powershell -file ". It's a bit ridiculous.

* Deeper Windowsy things like WMI or COM automation work infinitely better with PowerShell. In practice, the only time I use PowerShell is when I need access to something in this area; and then I'll take some arguments, do the PowerShell work, then output the results as text so I can do the main work in bash.

Powershell doesn't really feel like a shell to me. It's more like a SQL query command line and scripting language REPL hybrid. For example, something as basic as job control is almost non-existent. Forget about carefree application of '&' and 'wait'; that style of working, doesn't.

Re: PowerShell vs. Unix shells

#7

How much can you do with powershell regards system configuration? For example, could you put a Windows Server with PS behind SSH and login and config everything that way without having to touch the GUI?

Yes, this is the preferred approach since Windows 2008 Server Core. Please note that Powershell is only installed by default in Windows 2008 R2 Server Core.

You can then use Powershell remoting capabilites, or log into the server with SSH, like on UNIX systems.

Re: PowerShell vs. Unix shells

#8
The main difference between the two, in my humble opinion, is that PowerShell is a nice (and powerful) addition to a Windows system, whereas the Shell is a fundamental component of Unix.

Of course, the two shells may be equivalent in terms of power or number of features, and any contest a la "Can your shell do this?" would be futile. To me, it's a matter of cultural differences. Think of it this way: a shell operates in two mode, script or interactive (the new fancy word now is REPL). How much time does your average PowerShell user spend in REPL mode?

In comparison, a Unix hacker spends all his time in the shell, even for doing the most trivial tasks. As you practice more and more, the shell becomes a favorite way to operate a computer. Even tasks that may seem easier on a point-and-click interface (like selecting a few files from one directory and copying them into a new one) come more natural to me on the command line than with a mouse. The day I discovered that you can run 'for' loops from your interactive shell as naturally as a script, I almost uninstalled X :)

My only point is that the shell fits in the overall philosophy. You probably heard of the famous McIlroy vs Knuth story (legend?), where a pipe of a few commands turned out to be more efficient than a Knuth data structure. That's beyond my point. What I want to show is more the ending paragraph of this story, what McIlroy had to say about it:

> Very few people can obtain the virtuoso services of Knuth (or afford the equivalent person-weeks of lesser personnel) to attack nonce problems such as Bentley’s from the ground up. But old UNIX hands know instinctively how to solve this one in a jiffy.

That last sentence. Unix hands know how to solve these problems because of all the time spent on their command line.

Overall I'm glad that Microsoft is developing PowerShell, and I absolutely agree that it is far more adapted to their Windows platform than the old "all-is-text" mentality of bash and the POSIX tools. However, PowerShell is still treated as a second class citizen in the Windows eco-system, and that is, imho, its biggest weakness.

Re: PowerShell vs. Unix shells

#9
One problem with PowerShell is that it uses too much resources for a shell. I believe it to be superior in some ways to Unix shells, but I was never able to get (psychologically) past the 15 second or more startup time needed on my machine (Windows 7 netbook). Given that languages like Python have less starting times, I am likely to use the command prompt and/or scripting language every time.

I guess server people would not encounter this problem.

Post reply on HN