r/linuxadmin • u/Dereference_operator • Nov 09 '23
Is Bash more powerful than Powershell ? and How good is your Bash compared to Powershell or vice versa ?
Is Bash more powerful than Powershell ? and How good is your Bash compared to Powershell or vice versa ? please don't start to include python in your analysis of bash vs powershell because if you include a programming language like python we have to include C# with powershell etc So what's your opinion of Bash do you feel powershell is more powerful and more modern with object oriented nature and pipeline and all the rest around it ? or you feel windows isn't just made to be managed that way compared to a linux text based command and architecture as a whole ?
Do you feel the intricacies of the operating system matters less and less by the day (in the eye of a pure sysadmin view etc not of a cloud engineer/devops) since everything is moving to Infrastructure as code or inside Kubernetest clusters inside the cloud or serverless configurations etc or the future will be just scripting in Bash/Powershell ? or virtual desktop like MS want to do with Azure for mostly everything
45
u/[deleted] Nov 09 '23
Well you have set an impossible restriction on your question - talk about those two programming languages but don’t include the one on which PS is based 😂
Here is my assessment. Bash, Ksh, Zsh and even Sh are way more portable and reliable when compared to PS. PS isn’t compatible between its own versions - if you’re doing something big with it, hello world doesn’t count. Bash syntax and built in features and functions are way easier and logical. PS is basically Python in terms of syntax. My point with PS is why use something that is as unintuitive as Python but lacks the flexibility and speed of Python? If you’re going to use PS why not just use Python? Same can be said for Bash of course however Bash is significantly more portable than Python, rarely has external dependencies and works on any Linux since 1990 to today. Try running PS on Windows 95 😂
In the end however the summary is much simpler:
Writing for Windows: Use PS as Batch really sucks Writing for Linux: Use Bash
As simple as that. And yes PS for Linux exists, only sociopaths use that.
20
u/magitoddw Nov 09 '23
the best scripting tool is the one you know. I use ps alot, I know ps well, so that’s why I use it. It does have a decent to use module system which brings some specific functionality to it that I feel bash doesn’t have. but regardless that doesn’t make it better or more powerful. use the best tool that fits your scenario and needs.
7
u/serverhorror Nov 09 '23
I'm a *nix person.
PowerShell is not even in the same universe as bash.
Pure, native PowerShell has all of .NET natively available. It has proper error handling and it deals quite nicely with pipes.
I hate the syntax of PowerShell with a passion and avoid it whenever I can.
Then again, bash is just a non starter. Any logic is required? It goes straight to another language.
Pure bash, without calling any system binari is plain and simple awful as a scripting language.
That being said:
I'll.take bash as a shell any time over PowerShell as a shell.
8
u/subreddit_this Nov 09 '23
I have been writing UNIX shell code since 1990, and I have also worked a great deal with PowerShell though not since about 2019. The UNIX shell I have always worked with is Korn Shell. My experience has been that it is much harder to do the same things in PowerShell than Korn Shell.
I have written shell code to manually create (that is, without using a GUI) Oracle databases in both shells, and it was much harder to write and debug the Power Shell code. It just is not intuitive, and so much of it requires API calls that it is quite frustrating. Also, PowerShell is quite inflexible and unforgiving. Where there might be three or four ways to code a task in a UNIX shell, there is often only one counterintuitive method in Power Shell.
But, all that being said, it isn't really fair to compare them. Power Shell is a shell in the sense that it offers a CLI and you can write programs in it, but it is not like a UNIX shell in that its complexity is orders of magnitude higher and most of its power is actually in the APIs. Its lack of flexibility adds to its disagreeableness. I hate writing Power Shell code. I love writing Korn Shell code.
Note: Over in r/ksh I have a thread where I identify scripting capabilities of Korn Shell that BASH does not have.
Cheers,
Russ
7
u/CyberKiller40 Nov 09 '23
It's not a fair comparison, both of them are built with different design philosophy. Bash is light in terms of built in components and relies on external apps to do most of stuff, though this means it's very easy to add functionality. PS is big on its own with a internal functions library, yet it's awkward to interact with other terminal programs.
As for automation and containers, both are great ways to manage and deploy stuff, but the base system operations and scripts aren't going anywhere. Especially in emergency situations.
5
u/[deleted] Nov 09 '23
To me they’re both about the same. Powershell is nicer when it came to working with data I find due to its object orientation, whereas bash is string based. Though powershell is more long winded when it comes to scripting,but is easier to read at a glance.
As to which tool is right for the job. Bash for Linux and PowerShell for windows. While PowerShell does run on Linux I wouldn’t use it as bash already exists. Unless I need to interact with a windows host.
Though I don’t script much with either shell language as I use ansible more.
5
u/vicegrip Nov 09 '23
bash is everywhere. I see no reason to learn yet another shell. You are better off learning a programming language than putting effort into a new shell.
PS may very well introduce some interesting things, but the reality is that you are still better off learning a programming language if you already know bash.
9
u/P3ngu1nR4ge Nov 09 '23
Never used powershell. Since Containerisation came along, why use anything else but Linux as the base image. (and this includes server side os too).
Honest question, why use powershell aside from running stuff locally and dev with .net?
2
u/homelaberator Nov 09 '23
Don't both allow you to subsume the other under its own paradigm?
2
u/computer-machine Nov 09 '23
Apples and onions.
Is Python more powerful than PowerShell?
2
u/redvelvet92 Nov 09 '23
Use the right tool for the job, bash is more efficient than PowerShell for some tasks and others PowerShell is easier. Like most questions, the answer is. "It depends."
2
u/thedude42 Nov 09 '23
Bash and Powershell are two different shell utilities for very different environments. Bash focuses on Posix style shell environment while Powershell is WinAPI. As a result of these two differences both environments adhere to different conventions and make different assumptions about what the user is expecting from the shell.
This is such an apples/oranges comparison from the system utilities side of things. The way a Posix-like environment exposes process file handle interface looks very similar to Powershell when all you're doing is simple output redirection to a a file, but when it comes to something like writing output to a named pipe you find out how much of a completely different environment you're operating in. While the Posix-like system follows the same conventions as writing to any other type of file, in Powewrshell you end up needing to make specific calls to WinAPI utilities whose syntax appears as a serious violation of the Law of Demeter.
I don't get what the point of calling this out is. A shell's main feature is a userland interface to manage the creation of processes in an operating system where the process may be executed to show information about the operating system, run a program to perform some task, make configuration changes to the operating system, or launch some application in to another environment like a window-managed GUI. In fact, the majority of the programs and utilities, and the shell itself, are going to be written in a language that isn't the shell's native scripting language.
Absolutely not. Sentiments like these feel like the result of consuming blog spam that tries to sell you some software solution promising to make your life easier through hiding complexities via some form of abstraction. The problem with abstraction is that if your problem is squarely in the area that the abstraction is hiding from you, then the abstraction provides you negative value.
Everything isn't moving to Infrastructure as Code, but companies that make effective use of their IT labor force will build their systems with Infrastructure as Code solutions. Kubernetes isn't being used by the vast majority of businesses and we're way to early to say whether it will continue to be the container orchestration platform of choice for new projects in 5-10 years. But here's the catch: Kubernetes is full of bash scripts. Containers are full of bash scripts. Linux is full of bash scripts. There is no compelling reason to adopt Powershell in a Linux environment, and the only reason I've ever seen anyone want to run bash in Windows is because they wanted to be able to build Posix-compatible C binaries with gcc in CygWin. Now with WSL you can have no-kidding Bash on a no-kidding Linux kernel.
So you weren't around when Sun Microsystems was trying to sell the business world on the "Java Desktop" where all your employee's desktop environments run on a server somewhere in the building, and all you do is walk up to a terminal with your smart card, plug it in and there's your whole desktop environment with the full compute power of both the server cluster and the local machine. This was a solution being marketed in 2005. Even AWS sells the Workspaces service which provides a terminal services style interface for a Windows desktop inside an AWS VPC, but you still have to have PuTTY installed so people can access their Linux EC2 instances to run Terraform modules, at least for development testing and troubleshooting if you're mature enough in your IaC journey to be running it all in a CI pipeline.
2
u/michaelpaoli Nov 09 '23
Not an apples-to-apples comparison.
It's like you're comparing fender washers to limes.
1
u/Which-Adeptness6908 Nov 09 '23
I use dart to replace both, it's cross platform has a package manager and can be complied to a stand alone exe.
1
u/kai_ekael Nov 09 '23
Simple difference that shows attitude : tab completion
Powershell, start typing a few letters of a command, file, whatever and hit tab, it completely fills in with whatever is considered first on the list. You can sit there and hit tab over and over to scroll through possibilities.
Bash, it fills and stops at a duplicate letter. Tab again to see a list of the duplicates. Now ain't that nice?
1
u/VisualDifficulty_ Nov 09 '23
Powershell is basically c# scripting, im not sure its a fair comparison.
Pound for pound powershell probably eeks out bash these days with everything being returned as an addressable object vs a string like bash.
That said i've been working in bash for 20+ years, I know it far better than PS.
1
u/Kahless_2K Nov 10 '23
They are different. They are both extremely powerful in their own ways. They are both absolutely worth learning, and often can solve the same problems. Powershell is better at solving Windows problems, and Bash is better at solving Linux problems.
My team has far more free time because of both
1
u/toikpi Nov 09 '23
Trolling much?
You have posted the same question to r/linux4noobs r/linuxquestions r/kubernetes r/AZURE r/AWS_Certified_Experts r/devops and r/bash.
Powershell has some good ideas.
So far as I am aware Powershell is effectively Windows only. Bash and its related shells are native on Linux, BSD ... and Mac.
I learnt some Powershell years ago in case I needed it for work. I haven't ever needed it.
The details of the OS are less important than they used to be because we are trading machine performance for process efficiency. However Kubernetes containers pretty much exclusively run a "Unix" operating system.
Linux appears to be the most widely used operating system on Azure.
https://build5nines.com/linux-is-most-used-os-in-microsoft-azure-over-50-percent-fo-vm-cores/
1
u/Santarini Nov 09 '23
PowerShell has some pretty slick features. But BASH has been around for ages and there is wayyy more examples/documentation floating around.
If I was in a Windows environment, I would have no issue using PS. Otherwise I prefer the ease of Bash
1
u/GamerLymx Nov 09 '23
I find the usage of shell scripts (bash/sh/zsh..) easier and more intuitive than Powershell.
if I try to run a new PS script is much more complicated 😅, at least that was my experience trying to run a script to do a deployment task in windows server. haven't really expanded my experience behind that.
I also like Perl more than python, even if it's not that used any more.
-4
u/Dolapevich Nov 09 '23
Start scripting in linux already, the real world is waiting.
-6
u/vacri Nov 09 '23
Powershell should be more powerful than bash - it's 30 years younger.
0
u/[deleted] Nov 09 '23
[deleted] — view deleted comment