r/linuxquestions • u/nullificationer • 12d ago
Advice Is powershell the best object based shell?
I have been using powershell at work a bit and the more I use it the more I like it. Having an object based shell just makes a lot more sense than outputting plaintext. I was just wondering what the best object based shells are for Linux, is powershell the best even for Linux?
36
Upvotes
20
u/t0mm4n 12d ago
Not a shell, but I use Python for complicated scripts.
13
u/kudlitan 12d ago
isnt powershell available for linux iirc?
23
u/fprimex 12d ago
I think NuShell has Powershell beat, personally.
10
u/RustyHackerBoy 12d ago
I am full on linux guy since some time, but I really miss Powershell. I loved scripting in Powershell and you can do and automate soo soo many things. It's easier compared to bash, imho.
From managing AD, to setup multiple PCs at ones, to storage operations and even phishing campaigns... I found a way using PS to make my life easier.
My advice: Check powershell out and learn it. It's really cool and it help you in the future. I promise.
10
u/Fractional-_- 12d ago
I just like bash and fish. Not object based and that's why I like them.
11
u/Human-Cellist-1059 12d ago
It depends. If you own the data model of the cmdlets then its great. Ive had go inplement my fair share of cmdlets for internal tools.
However for systems scripting I hate to have to learn object oriented data models for each cmdlet.
I find bash simplicity more powerful.
6
u/p001b0y 12d ago
I like nushell. Everything is typed, structured data
4
u/particlemanwavegirl 12d ago
Nushell and it's not even closeÂ
9
u/TheTrueBlueTJ 12d ago
People really enjoy writing Powershell scripts? The syntax in my opinion is awful. Bash isn't that easy to write either, I totally get it. But to me, Powershell feels like last century. I'm sure you can do powerful things with it, as you can with any kind of scripting on the shell level. I looked at Nushell, which many recommended here and that already is a night-and-day difference to Powershell. Nushell looks like an absolute "hallelujah" moment for shell scripting.
6
u/Background-Item-2818 12d ago
Definitely not. PowerShell seems incapable of assigning arbitrary data to variables and instead casts them to strings. Fuckin terrible & super frustrating to work with.
1
u/lilith2k3 12d ago edited 12d ago
I think that is the wrong question to ask.
As far as shells go you have under Linux a broad variety of the traditional unix text based input and output shells. So Powershell offers a new approach to that old topic.
But the question is: Is a shell a good environment to work in? Or is it better to do things via Python or even Go?
3
u/BranchLatter4294 12d ago
Powershell is the most widely used one. It's fine and works well.
3
u/davidauz 12d ago
you'll have to pry my #!/bin/sh from my cold dead hands
1
u/daddyd 12d ago
i don't know, never used powershell, but you could argue that python makes a pretty good object-oriented shell.
2
u/RobertDeveloper 12d ago
Beanshell was best
2
u/WorkingMansGarbage 12d ago
Can you sell PowerShell to me? But like, actually? I've heard what you're saying before but the syntax is still scary to me
2
u/Enderby- 12d ago
I've found pwsh to be perfectly fine.
A nice added bonus is you can use dotnet classes directly in the scripts, which is handy if you need to do a little more than just scripting, but not enough to warrant writing an application.
2
u/Open-Adhesiveness-86 11d ago
The catch with pwsh on Linux is that objects only come from cmdlets. Anything native (ip, systemctl, lsblk) hands you back a string array split on newlines, so you're doing -split and regex again. You can paper over it with
jc --ps | ConvertFrom-Jsonor the -o json flags some tools have. Nushell at least ships parsers for a bunch of that out of the box.2
u/SDG_Den 11d ago
as an IT professional and linux hobbyist, i fucking hate PWSH for actual use as a shell. it feels overly complicated for a CLI interface, especially compared to bash, dash, fish, zsh or nushell. imo, a shell should be relatively straightforward to read and understand.
3
u/MBouh 12d ago
Objects don't make sense on a linux system shell. Linux system is based on files, and files have text names. Shell manipulate files and text.
If you need data structures, you're not doing shell anymore. And why not using python then ? Much more of a standard than powershell.
1
u/BeardedBaldMan Bluefin 12d ago
I wouldn't say it's the best, but it's what I use because I have years of experience in it.
Something can be more technically sophisticated than something else, but if you have a team who already know how to use something which is pretty good then pretty good wins out.
1
u/oldendude 12d ago
There are many such shells for Linux. I wrote one that you may want to check out.
- website: https://marceltheshell.org
- Github: https://github.com/geophile/marcel
- PyPi: https://pypi.org/project/marcel
The website has many examples of usage, but here is a preview:
Explore the current directory recursively, and sum up file sizes by extension:
ls -fr | map (f: (f.suffix, f.size)) | red . + | sort- ls -fr: List only files (f) recursively (r). This yields a stream of File objects.
- The pipe character works as in bash, and pipes the output Files to the next operator.
- map (lambda f: (f.suffix, f.size)): Given a file f, on the input stream, write a tuple containing the file suffix (the extension) and its size to the output stream.
- red . +: Reduce the tuples, group by the extension (indicated by .) and summing the sizes for each group.
Summary of features
- Builtin help facility.
- Read and write CSV and JSON.
- Tab-completion and other familiar command line keyboard shortcuts.
- Runs on Linux and Mac.
- Read from and write to databases. A database query results in a stream of python tuples. Similarly a stream of tuples can be inserted into a database.
- Run a command on all nodes of a cluster and integrate results.
1
u/polytect 8d ago
python shell?Â
1
u/itgforlife 17h ago
Imo the biggest benefits of PowerShell are that it:
I use all of those at some point or another. But if those aren't things that matter to you, then you could use whatever.
One thing that bash does better than PowerShell, specifically jq, is colorizing / prettifying json in console output. For some reason PowerShell is garbage at doing this by default.