Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The biggest problem with Python is there's always some divide between it's environment and shell. I don't think Perl had this problem as accessing the shell was built into the language.

There needs to be a modern language that looks friendly, is compatible with shell, and is apart of the shells environment.

I am one of many people who don't really care for shell, it's old, limited, and just plain ugly. Unfortunately it's still the best way to interact with Unix, so it should be built upon to keep compatibility.

Wouldn't it be nice to write shell scripts with objects and data structures?



Check out marcel (https://marceltheshell.org), which does this exactly. E.g. to explore the current directory recursively, find files changed in the last day, and then compute the sum of file sizes by extension for the qualifying files:

    ls -fr | select (f: now() - f.mtime < days(1)) | map (f: (f.suffix, f.size)) | red . +
- ls -fr: list recursively, yielding only files.

- select (f: ...): f is bound to each file from ls. If a file's modification time is within one day of the current time, then write that file object to the output pipeline.

- map (f: ...): f is bound to each file from the select, and mapped to a tuple containing the extension and file size.

- red . +: Group by file extension and sum sizes.

And shelling out from python is much simpler. Here is the same computation in python

    from marcel.api import *

    for ext, size in (ls(file=True, recursive=True) |
                      select(lambda f: now() - f.mtime < days(1)) |
                      map(lambda f: (f.suffix, f.size)) |
                      red(None, r_plus)):
        print(f'{ext}: {size})
marcel.api imports functions matching the commands (ls, select, and so on), and the pipeline yields an iterator, for neat integration with python loops.


> Wouldn't it be nice to write shell scripts with objects and data structures?

That's PowerShell - https://docs.microsoft.com/en-us/powershell/module/microsoft...


The idea is very good but they f..ed up the language with a lot of weird quirks. Also, the naming convention with "Get-" first doesn't scale. Auto complete is basically useless when thousands of cmdlets start with "get".

And Powershell is super slow when you deal with a lot of data to the point of being unusable.

Two years ago I worked on a project where we used Powershell a lot. It worked OK but I think next time around I would use Python.


Which idea exactly was good? PowerShell, to me, is just a typical Microsoft product full of bloat and redundancy. Microsoft couldn't produce a concise language if their existence depended on it.


Having a scripting language deal with objects seems a good idea. Also, easy interop with the .NET framework is good.

It would have been much better if they had used a variation of C= (which is a pretty good language)


Microsoft produced Typescript and Lean. Are those full of bloat and redundancy?



Seems abandoned.


still works


Also nushell https://github.com/nushell/nushell - it seems to be less verbose than powershell


Begs the question- is it nice?


It is nice, but they chose to leave some odd legacy stuff around.

For example, you can make a Win32 GUI app, but the console window still shows. So, you can hide it, but it flashes briefly anyway.

Also, there's weird overlap of features, sometimes because it's so easy to call out to dot net. Like, there's Start-Job, but there's also Runspaces and System.Threading.Thread. Makes it hard to find the "right way" to do something.


Start-Job is not the same as Runspaces - one uses processes, other one threads. Those who need performant option will know what to use.


There's also Start-ThreadJob


> Wouldn't it be nice to write shell scripts with objects and data structures?

IMO no, it wouldn't. The simplicity and flexibility of plain text piping beats out the more structured approaches. Sort of reminiscent of how HTTP ate the lunch of most all other RPC protocols (eg. CORBA) even though it wasn't even designed to be an RPC.


But you only have the option of sending unstructured, untyped bytes over the pipe, which means you waste CPU cycles parsing and validating at each stage. And all data has a type, so you may as well have strong typing in your shell.

HTTP ate everybody else's lunch mainly because corporate firewalls closed off competing protocols' ports but kept port 80 open.


Maybe you use a different kind of pipe. My pipes allow me to send binary, typed data, e.g. protobuf. For example: http://temk.github.io/protobuf-utils/ .

Do you know a good set of command line utilities to work with binary typed data?


You're still sending untyped streams of bytes through the pipes, which must be marshalled and unmarshalled at the endpoints.

PowerShell, by contrast, operates directly on objects with strongly typed fields.


Data are just bytes. You can serialize data into an encoding, or you can send a raw memory snippet. It's implementation detail. Binary data is not a problem for UNIX pipes. Perl has powerful pack/unpack methods to efficiently work with binary data.

Do you have tools to use this feature? If not, who will write them? Who will define a standard format to use? Who will extend the standard format, when necessary?


Turtle [1] is a reimplementation of the Unix command line environment in Haskell that permits you to run external shell commands but leverages the typesystem to provide structured values and reduce errors.

    Turtle> cd "/tmp"
    Turtle> pwd
    FilePath "/tmp"
    Turtle> :type pwd
    pwd :: IO Turtle.FilePath
    Turtle> touch "file"
    Turtle> testfile "file"
    True
    Turtle> rm "file"
    Turtle> testfile "file"
    False

Fish [2] and Oilshell [3] are two other efforts to create new shell dialects that improve usability while remaining somewhat backwards-compatible.

[1] https://hackage.haskell.org/package/turtle https://hackage.haskell.org/package/turtle-1.5.22/docs/Turtl...

[2] https://fishshell.com

[3] https://www.oilshell.org/


>I am one of many people who don't really care for shell, it's old ... and just plain ugly.

Egads laddie, it'll happen to you too some day.


Python actually has great support for pipelining with the lazy iteration protocol built into the language.

The problem arises when you need to chain executables together, rather than just Python code. It turns out that shells do some pretty complicated stuff with file descriptors and forking, stuff that you definitely do not want to DIY in Python. So "streaming" data from one executable to another means you buffer everything in Python runtime, even if you use async. This is fine for a lot of cases, but it feels wasteful and in elegant to me.


> There needs to be a modern language that looks friendly, is compatible with shell, and is apart of the shells environment.

Julia: https://docs.julialang.org/en/v1/manual/running-external-pro...

julia> prefixer(prefix, sleep) = `perl -nle '$|=1; print "'$prefix' ", $_; sleep '$sleep';'`;

julia> run(pipeline(`perl -le '$|=1; for(0..5){ print; sleep 1 }'`, prefixer("A",2) & prefixer("B",2)));

B 0

A 1

B 2

A 3

B 4

A 5


Objects would be a deadend but it would be nice if they had the option to return data structures. No reason why you can't have both text and strutured output.


So long as your shell language isn't object-oriented. We don't want PowerShell on UNIX.



Amen to that !


Then maybe Raku would be a thing for you: https://docs.raku.org/language/create-cli


Is `ruby` any closer?

or eshell?


Wouldn't ruby fit such bill?


A looong time ago I wrote a Ruby shell and named it Rubbish.


Or even Perl!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: