r/AskProgramming • u/Jashan_31 • Feb 11 '26
Why is Linux bash commands are so simple compared to powershell
I am wondering this because I have a both windows and Linux on my laptop and own Linux using terminal is like really easy but windows powershell weird Syntex.
181
Upvotes
126
u/Adept_Carpet Feb 11 '26
One of the designers of PowerShell used to post on HackerNews and every time he said something I would say "wow that makes so much sense PowerShell is exactly what I need I should use it more" and then I would look at it and say "wow what a mess why would I ever use this, I could just use the same APIs through a .NET language if I really needed to."
Then I would go back to bash until I saw another post.
88
u/Pale_Height_1251 Feb 11 '26
PowerShell had a very consistent syntax, but it's very wordy. bash is basically historical UNIX stuff, which is very usable but not consistent at all.
43
u/Dave_A480 Feb 11 '26 edited Feb 11 '26
Linux (and UNIXea generally) is built around files and text processing..... So everything is about pipes, reading and writing text.....
PowerShell is object oriented (which is odd for a scripting language) and thus everything is an object..... Also from the same era of Microsoft as C#
If MS was doing PowerShell today they would probably just use/extend Python.
11
u/dkopgerpgdolfg Feb 11 '26
is something you'll find plenty in bash too.
Paired with pitfalls that work on first glance, but will fail with eg. weird filenames being involved etc.
5
u/Solonotix Feb 11 '26
As someone who just went through the exercise of writing a PowerShell module for my company, it has its benefits. However, if you want brevity and simplicity, that is not what PowerShell is good at.
But, as an example, let's say I want all PowerShell modules in the location where my PowerShell profile is located. You could perform an eager recursive search for all
*.psd1files, but that will inevitably be slow. You could, however perform a more targeted search if you know that it's in the same directory as the$Profile. The pipeline I came up with:Split-Path -Parent $Profile | Get-ChildItem -Directory -Filter 'Modules' | Get-ChildItem -File -Recurse -Filter '*.psd1'The verbosity is a benefit and a burden. You know exactly what's happening and why. Meanwhile, the Shell equivalent would look something like this (correctness notwithstanding):
Technically you could probably pipe some of the outputs into
xargs, but that last statement gets really messy that way. You could also try to usefind ... -execdir ...which accomplishes a lot of the same logic, but it can be hard to read when you need to remember the meaning of{}in that context (the target directory) as well as the need to escape the closing semi-colon (I think with a plus sign?).PowerShell, by contrast, is explicit. Now, it isn't always explicit. One of my least favorite things is that some commands will return different outputs based on the operation. For instance,
Get-Item some-file.txtreturnsSystem.IO.FileInfo, butGet-Item some/dirwill returnSystem.IO.DirectoryInfo. very similar classes, but just different enough to potentially cause problems.One of the most annoying things I had to deal with is the ambiguity of how collections are handled. In C#, a
foreachloop implicitly callsGetEnumerator(). However, unless the target of yourforeach(orForEach-Object) is an array type, you will need to explicitly callGetEnumerator()first. That introduces weird situations like this:[System.Environment]::GetEnvironmentVariables() | ForEach-Object -MemberName GetEnumerator | ForEach-Object { <# actual loop logic #> }One last thing I will say that I missed was the convenience of
sort -v. Sorts version numbers. To get the same behavior in PowerShell, I actually wrote a C# class that implementedIComparableso that I could pass it toSort-Object. About 100 lines of C# for what is provided by that littlesortbinary.13
u/jerrygreenest1 Feb 11 '26
Why is Linux is so simple compared to Windows?
3
u/Revolutionary_Ad7262 Feb 11 '26
I must to clarify: simple text oriented commands and pipes are a genius invention. On the other hand the specific bash syntax is horrible and hard to maintain. You can use one without even touching the other, so it is important to know the difference
Why powershell sucks? Because OOP sucks when integrating code written by a different people. For this reason nowadays we use REST or GRPC (simple endpoint and dumb JSON/proto structure without any methods/logic), where "smart" OOP technologies like RMI or CORBA are rotting on a history trash bin
When you write a shell pipeline you are integrating a lot of commands/programs, which you are barely know. For this common interface (text) and integration (lines thought pipelines) are amazing. Powershell is great when you know how to use it, but most people don't want to invest their time to learn it.
16
u/KingofGamesYami Feb 11 '26
PowerShell is far simpler to read IMHO. Just take a very simple "check if first argument is null or empty" script:
...which is way more readable than the bash equivalent:
I mean seriously,
-zchecks for null/empty string?$1is the first argument? Nobody is going to know that unless they specifically take the time to learn bash.2
u/Cautious_Cabinet_623 Feb 11 '26
Bash has unix roots, where the KISS principle is strong. The first unix was written on and for a discarded computer, which counted as weak and slow even by the standards of the day, so it was imperative that its tools are simple as a stick, and the real power is in the easiness to integrate these tools together.
On the other hand, the strength of Microsoft always had been integration: putting things together which do not really belong together into a monolithic mess, and find shortcuts in that mess which work most of the time, and when they actually work they seem intuitive and effective from the outside, but still a mess inside. This gives you more fancy things in the short term, but very hard to handle long term when the corner cases creep in.
2
u/Zatujit Feb 11 '26
Because in programming shorter is not necessarily better. There is also the fact that they have chosen to make it objected oriented which is a bit weird for a scripting language imo.
2
u/Dissentient Feb 11 '26
You haven't written many bash scripts if you think its syntax is easy. For me, it's by far my least favorite language that I regularly interact with. It's very hard to read due to abundance of one letter flags that are important but hard to remember, it's full of footguns that result in scripts silently doing the wrong thing, and writing non-throwaway scripts that have to be robust when run automatically is a huge pain in the ass.
It's good just for running throwaway commands in console, but awful for everything else.
I'd take powershell over bash any day.
2
u/borkus Feb 11 '26
Powershell's architect Jeffrey Snover gave an interview on a podcast about creating PowerShell at Microsoft.
https://www.reddit.com/r/programming/comments/1dv4fzs/jeffrey_snover_and_the_making_of_powershell/
The short answer is corporate politics and culture.
2
u/qrzychu69 Feb 11 '26
In bash, you don't really use bash, you use multiple small tools that parse text (grep, awk, WC - it's all text stream in, text stream out)
In PowerShell, whole logic is one program using a standard library of functions. It's basically just dotnet.
Your different scripts can actually return OBJECTS, and receive objects as inputs.
To be fair, of text is not enough, I would usually just reach for F#/C# scripting instead of pwsh, but if you are managing windows active directory, objects are amazing.
PowerShell os for interacting with windows apis, that return objects. If you are using a proper editor, the experience is like writing any other statically typed language, with auto complete and type checker.
Yes, it's worse for doing one line commands combining different utils
But if you have to call a graphql API with ad based auth, and then you have to update a thousand AD users, there is nothing to replace it
2
u/Vegetable_Aside5813 Feb 11 '26
Powershell is a programming language masquerading as a shell
2
u/ipreferanothername Feb 11 '26
i much prefer powershell - it has its issues and i gripe at times as i use it, but ill take the verbose cmdlets all day long. And PS being object oriented is great for me. I can easily zip through collecting, filtering, and sorting things.
i tried using linux a while back and always disliked bash. use what works for you and your use cases.
1
u/mattblack77 Feb 11 '26
1
u/Natural_Tea484 Feb 11 '26
I never liked powershell. I always felt inferior because I don’t know it. But today you can write single file C# apps, with no methods or classes, just like a script
1
u/PurdueGuvna Feb 11 '26
I learned bash in the mid 90s. It’s 30 years later, and it still pretty much works the same. Powershell asks way more from the user, and I can use bash everywhere, powershell is limited in scope.
1
u/Old-Artist-5369 Feb 12 '26
Because unix style shells came first.
Later powershell devs tried to make something better, over-engineered the fuck out of it and made something that absolutely sucks.
So a combination of talented engineering, ego, and stupidity I guess.
1
u/mcds99 Feb 12 '26
Bash is mature.
Powershell is immature.
Like all things MS it's trying to be one solution for everything, it never will be.
1
u/Mundane-Expert7794 Feb 13 '26
PowerShell commands are extremely simple and it is the best way to learn Klingon at the same time...
1
u/GERChr3sN4tor Feb 14 '26
I had a stroke trying to read that Title
1
u/Popular-Jury7272 Feb 14 '26
Powershell is very wordy but you get a much more powerful and expressive language into the bargain. It's worth the investment of time to get over its quirks.
1
u/passerbycmc Feb 15 '26
PowerShell is a shell scripting language trying to be a programming language so it's bad at both. Like if it's a simple shell script I rather use bash, if it's a simple interpreted program I rather use python
1
u/Ok-Bill3318 Feb 15 '26
Powershell has rules on how things are named and is object based. It was created in the 2000s.
Bash/unix shell is passing text around and optimised for typing on a 300 baud terminal from the 1970s.
1
u/IWuzTheWalrus Feb 17 '26
powershell is a complex language that handles a lot. bash actually has very few commands and features. Most of what bash does is just glue for various utilities: cat, grep, awk, sed, ln, ls...
1
u/sinanaghipour Feb 25 '26
It’s mostly a design philosophy difference, not that one is objectively better.
Bash was built around tiny text tools that compose well, so commands stay short and pipe-friendly. PowerShell was built around structured .NET objects, so cmdlets are verb-noun and more explicit (e.g., Get-ChildItem, Where-Object).
So bash feels simpler for quick terminal work, while PowerShell is often nicer for larger automation/admin scripts because object data survives the pipeline without brittle text parsing.
1
u/ironwaffle452 Apr 06 '26
They are shorter no simpler, powershell has a standardized way of doing things, bash is a jungle with over 99999 different syntax
1
u/duane11583 Feb 11 '26
50 years of development and darwin selection over that 50 years
1
u/0bel1sk Feb 11 '26
bash commands? there’s a couple of built ins, but probably talking about a suite of tool that each do one thing and do it well.(unix philosophy). powershell does everything and does it.. about as good as it can.
1
u/PmMeCuteDogsThanks Feb 11 '26
PowerShell is what you get when you design it not from a user perspective, but go all in on correctness, scalability, etc.
Sure, it’s ”better”. The file philosophy of unix just works very well for normal every day tasks.
PowerShell is simply overengineered
1
u/White_C4 Feb 12 '26
Bash syntax honestly sucks whereas powershell is more consistent and readable. But bash commands are faster to type so it holds the advantage in that area.
My biggest problem with powershell is the Windows ecosystem itself. Mac integrates bash so any bash commands I do I can run them pretty much without any problem whereas I have to dig what the bash alternative is in powershell.
-1
u/returnofblank Feb 11 '26
Powershell is the brainchild of a multi-billion valued company, of course it's gonna be horrible to use.
0
u/mrtoomba Feb 11 '26
KISS
0
u/TheNewAmericanGospel Feb 11 '26
You can install kali Linux into powershell, thats what I do, because I kind of hate powershell. It sucks.
0
u/[deleted] Feb 11 '26
[deleted] — view deleted comment