4 ms·
Recent comparison of pwsh to bash - finding out if you have the compromised eslint plugin. It's a bit apples-to-oranges, also I would have used 'find -exec {}'
by nailer 8y ago
Recent comparison of pwsh to bash - finding out if you have the compromised eslint plugin. It's a bit apples-to-oranges, also I would have used 'find -exec {}' in the bash example, but it's still interesting:
bash (by Feross):
find . -type d -name "eslint-scope" -print0 | xargs -n 1 -0 -I % sh -c "(cat %/package.json | npx json version) && echo '(at %)'"
pwsh:
$results = @{}
ls -recurse -filter "eslint-scope" | foreach {
$file = "${_}\package.json"
$version = cat $file | convertfrom-json | select -ExpandProperty version $results.Add($file,$version)
}
echo $results | format-list
I quite like the Powershell version, even though the syntax is unfamiliar. $results is a real hash object, the JSON tools are built in and formatting is up to you (you could have it output Excel or markdown if you wanted). I don't really like '_' as the iteration variable but otherwise I prefer it.
- brazzledazzle 8y agoYou can use $psitem instead of $_. I think (don’t quote me on it) it’s shorthand for CLI use. Kind of like `?` being `where` and `%` being `foreach`/`foreach-object`.
- userbinator 8y agoIt's interesting how different opinions on the syntax are --- the extreme verbosity and "general bureaucracy" of PS is one of the things that puts me off using it unless there's really no other way. It feels like a weird mix of C#/Java, perl, and bash. Reading-Lots-OfWords_With-CapitalisationLike-This is just plain annoying. Perhaps because it reminds me of posts on various forums from users who would capitalise the first letter of every word.
- oblio 8y agoYou're being unnecessarily mean. First of all, there's no _ in sight in regular identifiers (99,99%). They're always CamelCase and Kebab-Case when including the verbs. Secondly, it's case insensitive so you don't even need to go CamelCase. Just lowercase-itallthewaytothebank :D Thirdly, it depends on what you want to do. You can use $_ and % and various Perlish shorthands for faster CLI usage, but it's your call. You don't have to mix, you can go full C# and just use the names or go full Perl and use the shorthands, it's up to you. And fourthly, that bureaucracy makes things very discoverable. Now you're used to bash, but bash & ecosystem suck hard the first few months, until you accumulate the baggage, sorry, the knowledge to use them proficiently :)
- pweissbrod 8y agoWhen powershell 1.0 came out I LOVED the concept of piping objects like so much streams. In my experience there were two camps of powershellers, the scripters and the programmers. The scripters, probably the more experienced folks would use abbreviations, shorthand and all-lowercase. The programmers like myself would predominantly use powershell on less-frequent occasions to glue our apps together and PascalCase and verbosity has already been burnt into our brains. Powershell, like perl, took that philosophy that welcomed both parties to write code as they pleased. But then powershells 2 and 3 and 4 came out, and all that stuff I learned in v1 became deprecated. And I wanted a powershell script that would just reliably run on any, say, windows machine 2003 or beyond. But when I google for something like 'how do I invoke an osql.exe query command? how to escape the quotes?', or, 'how to load a dll and having an adjacent config file and run a method?' I get so many different answers ranging from woefully misguided to version-specific to syntax so wildly different to the untrained eye they look completely different yet being effectively equivalent. I inevitably spend hours crawling google and cobbling together the bits that work cross-platform, document heavily and sit in amazement at how much work it took to do something one would think was simple. It's a shame but my experiences with powershell as an occasional user have shifted from enthusiasm to seeing it as an arcance even punishing experience when I'm used to bash or python. I hope this doesnt sound mean in any way, its just that when youre talking with a computer, words like grep/sed/awk and regular expressions bear a learning curve but once you get past that barrier it is much easier to communicate succinctly with the computer with what you really want to do.
- oblio 8y agoI think that Powershell lacks right now most an up-to-date free resource. I remember back in 2011-2012 I was working a lot with it and there was a Mastering Powershell e-book which sadly is now gone, except as random PDFs on sites. But it hasn't been updated. I'm not sure I understand the thing about deprecation. I don't think Powershell has very many backwards incompatibility issues. What bit you the most? Also, I think after the recent switch to Powershell Core, they're not going to go for breaking changes. They can't, if they want to have any kind of cross platform adoption vs bash & co.
- 8y ago
- megaman22 8y agoAt least the Powershell doesn't have the incomprehensible argument soup, but that's more the fault of ancient Unix utilities that arose in the days when characters were precious. I don't do much actual Powershell scripting, but I can tell pretty easily what this should be doing without going to man files.
- grumpydba 8y agoCharacters are still precious. I spend my life typing commands and hate poweshell's verbose syntax. It just doesn't flow.