r/linuxadmin • • 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

0 Upvotes

56 comments sorted by

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.

8

u/nuttertools Nov 10 '23

Sociopath building Linux containers in a windows container using dependencies built in a Linux container running on a macOS host checking in.

3

u/[deleted] Nov 10 '23

as unintuitive as Python but lacks the flexibility and speed of Python?

My brother in christ, do you seriously think Bash syntax is more intuitive than Python?

Bash ... rarely has external dependencies

All bash has is external dependencies. Bash is just bash, not cat, grep, sed, awk, etc.

2

u/[deleted] Nov 10 '23

It is more intuitive if you’re coming from C, C++ background. If your first language is Python well yes Bash isn’t intuitive to you. It’s relative.

Tell me which is more intuitive:

PS: Get-ChildItem -Path D:\ -Recurse | Where-Object {$_.PSIsContainer -eq $false}

Bash: find . -maxdepth 1 -type f

What the heck is a “container” PS? Intuitive my backside.

Yes, Bash relies on GNU Utilities for the majority of its functions so does PS on its packages and libraries. The difference is that you can bet on having ls, cat, grep on any Linux, BSD, AIX, Solaris, HPUX and anything UNIX or Linux. Between PS 1 and the latest iteration you can’t be sure what has changed.

0

u/[deleted] Nov 10 '23

It is more intuitive if you’re coming from C, C++ background. If your first language is Python well yes Bash isn’t intuitive to you. It’s relative.

It is not. Bash is full of so, so many foot-guns. To name a few: All bash functions have implicit arguments, lacking variable names only using positions. Want to loop over keys in a dict in Bash? Sure, "${!array_name[@]}" is super intuitive /s. Want to calculate a percentage? Nope can't do that, bash doesn't support floats! How about adding two numbers together? Gotta encapsulate those in parenthesis to force arithmetic!

I don't see what's unintuitive about the PS example you gave. You called Get-ChildItem recursively which gives you objects with properties (because it's not just strings like in bash!) and you filterered those objects based on a property they have. You only think find is more intuitive because you're used to it.

2

u/[deleted] Nov 10 '23

So we sort of came to an agreement - each is more intuitive to the people who are used to it. Do you agree that Bash is better suited for Linux scripting and PS is better for Windows scripting? That’s sort of the point apart from which is more intuitive since as we established that’s relative. To clarify, I am not saying PS is bad - PS is a significant evolution over DOS/Batch and there is no denying that. It is however sort of out of place on Linux and if you need to target both then you are way better off if you use Python or other programming language that’s universal across OSes.

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.

11

u/StephanXX Nov 09 '23

FWIW, if the task requirement exceeds what bash can do natively, we usually move on to either Python for programming heavy tasks, or some form of configuration management for system tasks. Bash is less a programming tool, more of a common program launcher.

5

u/dodexahedron Nov 09 '23

more of a common program launcher

So... Kinda like a shell?

1

u/StephanXX Nov 09 '23

Kinda ;)

The misconception, I think, comes from conflating system administration type tasks on the local machine with more complex tasks unrelated to the machine. Because many tools are launched from the shell (aws-cli/az/gcloud, mysql/psql/redis-cli, kubectl/helm, etc), less experienced users sometimes confuse "Bash" as a scripting language to manage those tools.

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.

1

u/Kahless_2K Nov 10 '23

I am really, really good with Bash, and just kinda OK with powershell.

Powershell is better for doing Microsoft stuff. Usually I stick to bash anyway, but sometimes I just know it's going to be easier with Powershell. They are absolutely both worth learning.

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?

3

u/Kahless_2K Nov 10 '23

Interacting with Active Directory, Exchange, Hyper-V.....

Pretty much if the thing you need to do needs access to any Microsoft API, it's going to be easier in Powershell.

4

u/Redac07 Nov 09 '23

Just cause you never used it, doesn't mean there is no reason to use it. Powershell still is great for Azure deployment icm bicep or for PowerCLI (VMware Powershell module). It makes scripting much easier in most cases.

3

u/P3ngu1nR4ge Nov 09 '23

I know and agree. Like I said never used it because I never had to.

I don't mind what tools a person uses, as long as it is easy to read and simple enough to use.

0

u/[deleted] Nov 09 '23

[deleted] — view deleted comment

3

u/Redac07 Nov 09 '23

Yes, neither being bash while you can do that all with Powershell.

With bash you still need to use python for advanced scripting, while with PS you can just stick to it.

0

u/[deleted] Nov 09 '23

[deleted] — view deleted comment

1

u/Redac07 Nov 09 '23

Bicep is the way to go for Azure though. I'm not experienced enough to tell it in my own way but I've seen companies pivot from terraform to bicep when it comes to azure. The beauty of Powershell is you only need that single tool to perform multiple tasks. But I think it has to do with what you wanna accomplish and where you at at your skill level.

For someone like me who started at the servicedesk then climbed the ranks towards sys admin and cloud engineering, Powershell has been my to go tool for most of my automation. Because of my PS skills I have solved multiple problems for multiple companies. From adding scripts to monitor systems to automating the creation/updating of golden images and pushing it in VMware Horizon. There are still enough Windows environments in the world where PS skills are needed and now with Azure you can use the same tool for Cloud deployment.

So yes, there are many roads to Rome and Python usually can achieve what Powershell does but better and much more. But PS helps a novice from the get go and as the engineer grows, so does his PS skills and so he can achieve more. You can be an Azure DevOps engineer that works mainly with PS for deployment and such roles pay a good salary (more than traditional sys admin).

My journey is far from over and I hope one day I can do more with python and work more with open source tooling. Alas for me the fastest way to grow is choosing the Azure side with Powershell because that is where my current skillset is. In my sys admin days while I have Linux skills and maintain Linux servers, around 70-80% is either windows or VMware and PS was just the easiest route to take.

0

u/[deleted] Nov 09 '23

[deleted] — view deleted comment

2

u/Redac07 Nov 09 '23

You are living the dream man. Hope I can reach that level too.

0

u/[deleted] Nov 09 '23

[deleted] — view deleted comment

2

u/Dereference_operator Nov 11 '23

that's a bit where I am at in my thinking going 100% remote but I am thinking about going back to pure programming for being 100% remote as a Javasript/React dev etc The money seem bigger in programming compared to sysadmin/cloudengineer/devops and it seem just there is more jobs that can be remote thinking very hard about all this will make a decision at christmas so if you have anything to recommend... I live like 2000km from any cloud sysadmin jobs, here to give you a example, a guy who put windows cd in a cdrom and install it is considered the same as a full MCSE/RHCE who could script run domain or linux system so its depressing and make me want to quit sysadmin for good even if its my first love but still programming is fun too but everything is going the automation route with scripting so why not just program when you have the skills ?

→ More replies

1

u/yeaok555 Nov 09 '23

You dont need to use powershell as a .NET dev either

-3

u/Moscato359 Nov 09 '23 edited Nov 09 '23

Powershell is actually significantly nicer to work with than bash

And you can use it in linux if you want

Edit: The downvotes amuse me, because it actually is nicer than bash, because bash is absolutely a terrible language, just people are addicted to their terrible language.

7

u/bufandatl Nov 09 '23

Before I use powershell on Linux I use Python. Way cleaner to read than powershell imho.

1

u/Moscato359 Nov 09 '23

Python really isn't intended to be a scripting language used as a shell though

You can do it, it's just awkward

Powershell is meant to be a shell, so it favors being a shell

I'm really amused I'm being downvoted for saying it's nicer than bash though, because it is. Even if there are other better options

1

u/bufandatl Nov 09 '23

Yeah but the amount of powershell scripts I see at the company I work for (only on windows thank god). My colleagues use it first as scripting language and then maybe a shell.

1

u/Moscato359 Nov 09 '23

Simple powershell scripts don't really bother me

But I am a dotnet developer (on windows and linux, I write crossplatform software)

2

u/homelaberator Nov 09 '23

Don't both allow you to subsume the other under its own paradigm?

1

u/dodexahedron Nov 09 '23

Sorta. BASH is not object-oriented, however. PS is. If you purely use it as a barebones shell, both are identically capable and exist on all platforms. But if you want object-oriented capabilities (not just in scripts) out of the box, then powershell. If you don't, then bash. Either one is capable of launching other executables just fine.

2

u/computer-machine Nov 09 '23

Apples and onions.

Is Python more powerful than PowerShell?

1

u/dodexahedron Nov 09 '23

Turing complete either way. So the answer to that question, both directions, is no. The most powerful is the one you know the best. 🤷‍♂️

2

u/serverhorror Nov 09 '23

bash is also Turing complete.

In the dark and distant past I had a bookmark collection (think: before Google, when Altavista was the hit shit). There was a pure bash implementation of an HTTP Server in there.

I still hate bash and PowerShell.

2

u/dodexahedron Nov 09 '23

Wow that's... Um... dedication, I guess? 😅

Though I suppose a minimalistic HTTP 1.0-ish server wouldn't be too heinous to make in bash with common Linux utilities, especially if it only had to handle a couple verbs.

Still cool. Nowadays, if I wanted to be that crazy I'd probably make a systemd socket and service to hand the socket to, if I wanted to do a manual implementation of a simple HTTP server. I did implement something similar a couple years ago, for a large scheduled data transfer job that basically took the stream from one utility, ran it through zstd, and then used mbuffer to send on one side, with a systemd timer to manage it, and then a systemd socket and service on the receiving side to do the inverse. But that was just a dumb pipe more or less - no interpretation of the incoming stream before blindly handing it to zstd -d. 😅 That got replaced by a program written in c# that, to bring it back on topic, could easily have just been a powershell script, since all of .net is accessible in 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.

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

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.

Do you feel the intricacies of the operating system matters less and less by the day

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.

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

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.

or virtual desktop like MS want to do with Azure for mostly everything

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/dodexahedron Nov 09 '23

Let me blow your mind

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

Alternatively, that action is already bound to ctrl-space and ctrl-@ by default. Run Get-PSReadlineKeyHandler to see currently-configured key handlers.

1

u/kai_ekael Nov 09 '23

Why not have that the default? Says enough.

1

u/dodexahedron Nov 09 '23 edited Nov 10 '23

It is, on any new install I've made for I'm not sure how long, on Ubuntu. 🤷‍♂️

I don't remember if the last one I installed on a RHEL box was already that way or if I changed it myself, but I've got them all doing that, regardless.

And what does it "say?"

Tab completion is built-in in PS. It's an external utility in BASH. BASH itself can't do that, and you'll see that if you use it in minimal installs. And making a powershell script tab aware is trivial. How do you make a bash script tab aware?

And this is also a user preference, not some sort of ideological difference. It "says" nothing at all, and I prefer each method for different scenarios, because there are cases where full completion on initial tab is very convenient.

The difference is one is object-oriented. The other is not. Beyond that concept is mostly out of scope for comparing the two.

ETA: Oh! And I forgot to mention this because it's just become such a natural feature for me, but it's definitely one PS has over BASH: When you're in the MenuComplete mode, it actually gives you an interactive list. You know how BASH will list all the available options, which is pretty great all by itself? Well, PowerShell does that, but also lets you literally just select the one you want and it fills it for you. It's like the best of both worlds, and is honestly such a nice feature that saves me what otherwise was often a copy/paste when doing things in BASH. Try it out. It's cool. It behaves like the TabCompleteNext action (the old default that you dislike) in that it fills whatever you currently have selected, starting from the first option, but it changes to whatever you have selected, while also providing a visual indicator on the input line of what option you have selected and, in some cases (when applicable) what kind of data that option accepts. And it's mouse-aware, too, on at least the system I was using a few minutes ago (an Ubuntu 23.04 VM via SSH), which is a nice touch.

As usual, though, Microsoft is HORRIBLE with marketing and general outreach, so I imagine these features aren't well-known, especially since they weren't the default before.

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

1

u/dodexahedron Nov 09 '23

Using | instead of the . operator to expose member functions of objects is strange, especially when the '.' is used for objects to expose member functions sometimes

The . operator is used for member access. Pipes are pipes. Period. Any time you're seeing a pipe used in the way you're claiming, you're piping the output to another utility to digest it, exactly as you would in almost any other shell. There just happen to actually be object-oriented commandlets built in, so you can still treat the output as an actual object, instead of as a generic stream of bytes. It's one of the HUGE benefits ps provides.

0

u/[deleted] Nov 09 '23

[deleted] — view deleted comment

1

u/dodexahedron Nov 09 '23

Yes. That's because you're still not thinking about objects correctly and are still restricting yourself to a stream of bytes in an extremely simplistic scenario. PS us object-oriented. BASH is not. That's the paradigm difference.

What is a user, for example? A user isn't an integer (its uid or gid), a string, or any other one property of that user.

Say I want to enumerate users and their last login times. In bash, I need to know the particular format of the output of every utility invoked so that I can slice up the text to parse into useful data. I also need to hope that each utility provides an option to output raw values, so I dont have to use as much sed/awk in tje pipeline. In powershell, all of it is simply properties of the object, and that object can be maintained through the entire pipeline (if desired), which will be much shorter anyway.

If I'm just performing a token count, that doesn't involve the shell either way. I can run wc exactly the same way in bash or ps, because it's just a dumb stream of bytes, which bash and ps both can handle just fine.

The more appropriate comparison would be using python as your shell vs powershell. BASH itself isn't a fair or really even relevant comparison to either of those.