4 ms·
If I had a nickel for every time I had to debug some crazy Bashism. PowerShell can be finicky at times but is a walk in the park compared to the alternatives. F
by Riverheart 4y ago
If I had a nickel for every time I had to debug some crazy Bashism. PowerShell can be finicky at times but is a walk in the park compared to the alternatives. For basic stuff like if/else comparisons I don’t need to lookup how many parens or square brackets to use for strings or arithmetic or recall if 0/1 is true false or reverse. Maybe I should just compare “false”/“true” strings or use true/false commands instead which have their own issues.
PowerShell has real functions, not just exit codes and text streams so you can easily write maintainable scripts past 100 lines. It’s got a debugger. It’s got modules and a package gallery. It’s got autocomplete and help messages. It’s got try/catch/finally instead of traps. It’s got an optional type system so you can be as loose or strongly typed as you want. It’s cross platform so the Windows devs don’t get confused migrating to Linux. It’s got batteries included for everything between cmdlets and .net. Anything you can do in C# can be replicated. Sed/awk/Grep are nice but sometimes you just want structured data converted into an object to pass around functions instead of reinventing the wheel.
Case sensitivity is a feature, $foo and $Foo should be the same and if they’re not you should call it something different or invoke it differently. “$foo = new [foo]” separates variables from types. “$env:foo” namespaces your env vars. In Bash is FOO a var, constant or env var?
Good PowerShell is readable with little effort. Good Bash is readable with significant effort if you are familiar with Bash and the problem domain already.
- ggorlen 4y agoCase sensitivity isn't a major deal, but it's another example of the designers trying too hard to be clever and "user friendly". A good scripting language should try to reduce friction relative to other programming languages, most of which are case sensitive. I'd like to see a native OS scripting language that has a low bar of entry, isn't silent on undefined variables and other common mistakes, imposes syntactical consistency like Go or Python, has decent basic data structures and isn't riddled with pitfalls. PS isn't that language. If Bash and PS were good, it'd be so much easier to bring non-programmers into the command line so they can automate tasks and hack on their systems. Unfortunately, these languages aren't doing that, much less passing the usability test with most programmers who'd just assume script with Py, Perl, JS, or whatever their preferred language is.
- Riverheart 4y agoPython/Perl/JS/Ruby aren’t shells so the busy sysadmin doesn’t need to ask themselves at what point they rewrite their script in a sane language and a Windows dev won’t typically use those languages, especially as you’d have to call the Win32 api for lots of behavior or bring in many external packages for things PowerShell includes for free. In terms of ease of use PowerShell and ISE is available on every PC, is more consistent than Bash and more powerful than a user friendly shell like Fish. I don’t know how you get easier than Get-Foo, Set-Foo. Bash doesn’t really offer anything out of the box except the ability to glue external commands together and most people use it because of its availability and portability rather than its virtues as a language. Zsh, Fish, Elvish, Xonsh haven’t managed to displace it and Xonsh is even written in Python. The only thing I can think of that could make automation more friendly to nontechnical users is something like autohotkey to mimic manual interaction.
- ggorlen 4y agoThe point is, if a developer is resorting to another language just to write a 20 line script with a data structure, a loop and control flow, that's a failure of the shell. I don't want to have to use anything other than PS to script on Windows, but I'm often forced to in order to be productive. It's not saying much for the language that Windows sysadmins use PS primarily. Like Bash, the reason people use it is availability, not language virtue. See last year's Stack Overflow developer survey, where Bash was more popular than PS (29% (Bash) to 12% (PS)[1]) and loved (57% (Bash) to 43% (PS)[2]). I don't like Bash. I'm using it as a yardstick to show how disappointing PS is. [1]: https://survey.stackoverflow.co/2022/#most-popular-technologies-language https://survey.stackoverflow.co/2022/#most-popular-technolog... [2]: https://survey.stackoverflow.co/2022/#technology-most-loved-dreaded-and-wanted https://survey.stackoverflow.co/2022/#technology-most-loved-...
- eviks 4y agoPython is a shell, the one you mentioned, xonsh And PS doesn't include things for free, it brings a lot of baggage from the same company that made the win32 APIs unergonomic, though it does have a few structural advantages like typed data (the easier part to Get-/Set- could be losing the pinky-typed dashes since you already separate by Case, and for such common things you could even just use gFoo sFoo) But none of these options are anywhere close to the ergonomics needed to bring non-technical users into the fold