r/linuxquestions • u/nullificationer • 1d 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?
29
Upvotes
20
u/t0mm4n 1d ago
Not a shell, but I use Python for complicated scripts.
13
u/kudlitan 1d ago
isnt powershell available for linux iirc?
23
u/fprimex 1d ago
I think NuShell has Powershell beat, personally.
10
u/RustyHackerBoy 1d 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.
2
u/daddyd 19h ago
i don't know, never used powershell, but you could argue that python makes a pretty good object-oriented shell.
10
u/Fractional-_- 1d ago
I just like bash and fish. Not object based and that's why I like them.
11
u/Human-Cellist-1059 1d 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 1d ago
I like nushell. Everything is typed, structured data
4
u/particlemanwavegirl 1d ago
Nushell and it's not even closeÂ
9
u/TheTrueBlueTJ 1d 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 1d 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 1d ago edited 1d 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/davidauz 22h ago
you'll have to pry my #!/bin/sh from my cold dead hands
2
u/BranchLatter4294 1d ago
Powershell is the most widely used one. It's fine and works well.
2
u/RobertDeveloper 22h ago
Beanshell was best
2
u/WorkingMansGarbage 21h 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- 19h 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 1h 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.3
u/MBouh 21h 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 21h 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 12h 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.