A recent example, looking for errors in windows logs:
Get-Childitem "C:\Windows\" -recurse -Include *.log ` | Select-String "Error" -ErrorAction SilentlyContinue ` | Group-Object filename | Sort-Object count -descending
Closest *NIX analogue I can think of would be grep -r Error /var/log/ | sort
English is an arguably fine speaking language but an awful programming one.I love what Powershell can do, but gods do I hate typing it.
The equivalent to the UNIX line above in Powershell is:
ls "C:\app\*.log" -R | sls "Error" | sort
You cannot just tack on a bunch of extra requirements for Powershell (grouping, sorting by certain things and in a certain order) and then not include them in the UNIX example, that's disingenuous/misleading.The only big difference between PS and UNIX in an actual analogous example is that the PS version of grep gets files fed in one by one and processes them, whereas UNIX's grep processes files itself.
PS - The above Powershell code may not work in 2.0 (2009). You'll need 3.0 (2012) or higher.
By the way, your example is precisely 12 characters longer than mine and still multiple times shorter than the equivalent PS, so if your goal was to somehow disprove PowerShell's annoying verboseness rather than snark at me, you failed.
Then check your examples before you post them to make a specific point. It is a point of fact that calling those two things "analogous" is incorrect, and your offense doesn't change that fact.
You also specifically said "I can think of" implying that you created the examples rather than that you got them from an "internal wiki." The fact that you said you thought of the UNIX example gives me solid ground to describe the created example as disingenuous.
I cannot help it if you're being misleading about how your got your examples.
> By the way, your example is precisely 12 characters longer than mine and still multiple times shorter than the equivalent PS, so if your goal was to somehow disprove PowerShell's annoying verboseness rather than snark at me, you failed.
My point was your examples were poorly constructed and misleading. I proved my point I believe. The difference between my accurate example of PS and your inaccurate example are night and day.
I'll leave it up to the reader to decide if PS's syntax is more to their liking. I just think they should start off with accurate information so they can form an accurate determination themselves.
In other words I won't get drawn into comparing my PS example with your UNIX example. I just want both examples to be truly analogous of one another.
I think you didn't realize, but what Someone1234 has there is the equivalent PS, not UNIX shell.
(iwr "http://Slashdot.org").Links | select href
Nearest Unix equivalent please. lynx -dump -listonly http://Slashdot.org
Not exactly, but close. Needs more work if you want to pipe it further. curl http://slashdot.org/ | grep -o "href=[\"'][^\"']*" | sed -e "s/href=\"//"
But presumably this is being discounted due to the lack of HTML parsing, so not the same as the Powershell example. Then one somewhat ugly method would be using the html xml utilities provided by the W3C and available on most package managers: curl http://slashdot.org/ | hxpipe 2> /dev/null | grep Ahref | sed -e "s/Ahref CDATA //"
Obviously not as pretty, but it does do a nice job of going through the HTML tree, and doesn't rely on nicely formed XML that /usr/bin/xpath would.I'm not sure how robust your hxpipe example is against those.
But since you asked, hxpipe assumes that href on a non anchor tag is an error and should be represented as an Ahref... which isn't too bad an assumption to make, tbf. The other situations is dealt with (text content, javascript).
But really, taking the above into consideration, the might in powershell comes not from the terms used, in my opinion, but how it works on things. With grep for example, you're parsing a file. If say, you wanted to filter on that more, you'd be using awk to pick out parts of the text.
In Powershell, everything's an object. Everything's already an object, you don't need to pick the file apart to isolate the date, you just filter on the date object. It's got a data type.
That makes it really powerful, in my opinion.
(Example largely pulled from "Windows Powershell in Action". I really like this book, as it goes into detail to describe /why/ things are they way they are in PowerShell, because he wrote it. =) https://www.manning.com/books/windows-powershell-in-action-s...
Not really, as everything is given an unreadable alias anyway, and many are given multiple aliases: Copy-Item -> copy,cp,cpi. So there are just more names to learn.
Personally, I never use them. I saw them more as a help for people coming over from bash.
For the thing to become usable, you have to do personal configuration, meaning your system will be unusable to anyone else and theirs will be unusable to you.
Back to the drawing board...
Cumbersome. To create my own cmdlet that does the cool stuff Powershell can do (as far as piping) my choices are a terrible language like ps1 or .NET.
On Unix I can use pretty much whatever I want because the shell isn't tied to a specific runtime.
If you want, your PS commandlets can return strings as well, so it's not like every part of your pipeline has to be in PS either.
The whole design of PS is meant to make it so you can "guess" the names of cmdlets you've never used before. Everything is Verb-Noun, Get-Service, New-Service, Restart-Service, Stop-Service, etc.
Discoverability is valued over succinctness.