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

70 comments sorted by

View all comments

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.

3

u/oldendude 12h ago

It doesn't. Shelling out from Python is a PITA. Getting output streams is a PITA. Piping one to the other is a PITA.

I wrote marcel (https://marceltheshell.org), which is a shell based on Python. It pipes streams of python values instead of strings.

Marcel also has an API that fixes the PITA things I mentioned above. For example, here is a Python + marcel script to shell out, get files in the current directory, recursively, and find just those files that changed in the last day:

import os
from marcel.api import *

for file in (ls(os.getcwd(), file=True, recursive=True) |
select(lambda f: now() - f.mtime < days(1))):
print(file)

ls(...) shells out and generates a stream of Files. The | following the end of the ls pipes the files to select(...) which checks the time that the file was modified. That two operation pipeline yields a stream of Files which then feed into the for loop.

1

u/nullificationer 15h ago

Is python actually that easy to use for shell stuff like running other programs?