Live data from Hacker News

Four features that justify a new Unix shell

oilshell.org

141–150 of 185 posts

Re: Four features that justify a new Unix shell

#141
post #82

I'm sorry to say to for me, shell scripting has lost. All my scripts are written in Python, which a thin shell script wrapper to launch it. Look at Oil. It tries hard to be bash compatible with optional buy-in to extension. Just use a superior language and give up on shell scripts, that's my advice.

I'm curious what scripting tasks you do with python? I've found bash to be more than enough for everything I'd like to script, except for maybe stuff with heavy json processing (still doable with `jq`)

Anything with a non-trivial program flow, e.g. "do thing A, B, or C, and optionally mixin arguments D and E, with caching in between the shared steps."

Lots of deploy scripts look like this.

Re: Four features that justify a new Unix shell

#143

Doesn't TCL (and tclsh) handle these top four features quite elegantly? I understand why people shudder at TCL, but they are mixing up the elegance of the language with the dysfunction of the situation it was pulled in to address. Yes, when you start gluing random stuff together it gets ugly. This is true in real-life too. That's the situation. TCL, from the "commands and strings" handles this quite elegantly with a…

TCL has a very simple model of a shell "REPL": interpret string as expression and evaluate.

In contrast, a Unix shell has job control, stderr, pipes, etc.

Re: Four features that justify a new Unix shell

#144
post #130
post #99

Earlier quoted context omitted.

> The paragraph right below that mentions that Oil has "read -0", which consumes the find -print0 input. Yeah, I read that ("read -0", for the record, is an excellent idea). QSN for filenames still a bad idea. Your wc, awk, grep etc commands will now have to decode the stream after splitting it. Taking it to the extreme, it's like mixing JSON and XML (or CSV and TSV) because some things work better in one or the othe…

A bunch of points: (1) Except when your tokens can contain newlines, which we're stuck with for the foreseeable future. -- not sure what you mean here, because QSN strings are defined not to contain literal newlines. They're escaped like '\n'. The invariant of QSN is: EVERY BYTE STRING, including those with newlines and nuls, can be represented on a single line. I guess I should put this in the documentation. (2) A Q…

> (1) Except when your tokens can contain newlines, which we're stuck with for the foreseeable future. -- not sure what you mean here, because QSN strings are defined not to contain literal newlines. They're escaped like '\n'.

The tokens in question are filenames, which are (and will continue to be) allowed to contain newline characters. Sorry that wasn't clear. This was never meant to be a critique of QSN, I'm just saying QSN is unnecessary and unnecessarily complex for between-process communication:

- In case of filenames, just use NUL. It already works, is supported by a bunch of tools, and will never have the overhead of encoding/decoding.

- In case of arbitrary binary streams, just send the stream unaltered. Why encode/decode it? What benefit is that? In the very rare case that I'm actually manually inspecting a stream of bytes (debugger/printf) there's always some easy way to encode those bytes for easy readability such as `printf '%q\n'`.

> (2) A QSN decoder is very easy to write. For example, here's a ~6 line regex that validates all of QSN:

It would take me at least a day to write enough test cases to ensure that that regex in fact does what it says. But the point is moot: encoding and decoding should only happen at the interface with a human, not with another process.

> (3) Oil should grow [2] an awk-like dialect [3] that understands QSN and QTSV.

I couldn't comment; I don't use awk unless I absolutely have to. Once I need to use awk a shell script is no longer the best tool for the job, except for quick once-only processing.

> (4) Although you also don't have to decode it for it to be useful.

> 1. I can use wc -l on a stream of QSN strings

I can already use `wc --files0-from=-` on a stream of NUL-separated tokens.

> 2. If I know the strings are QSN-encoded, I can search for NUL bytes with fgrep '\0'

You can already `grep` for NUL bytes[1].

> (5) base64 is bad for humans at the terminal, because it makes everything unreadable. QSN preserves all printable ASCII and unicode.

But filenames are neither ASCII nor Unicode - they are bytes, which can include 0x80 through 0xFF (not valid ASCII) and things like 0xFF (not valid UTF-8).

I still can't see a single use case where I'd want inter-process communication to use QSN. Human input, sure, I'd love something more convenient that `$''`. Human output, also sure, humans can't read NUL characters or tell the difference between spaces and tabs after all.

[1] https://superuser.com/a/612336/2259

Re: Four features that justify a new Unix shell

#145
post #66

Earlier quoted context omitted.

There is a better option and its name is Perl. Perl mixes the ins of shell scripts like easy argument and output passing with complex and easy to use control structures. You could use Python, but having been forced to use Perl extensively Perl is the superior choice for a complex shellscript-like workload. There's less boilerplate in Perl. There's a couple Python projects that come close like Fabric, but Perl was lit…

There is nothing in the (IT) world I fear more then... Perl projects. The shear madness it will leash upon you when the dependencies fail is maddening. Never will I voluntarily touch anything written in Perl ever again in my live. I've seen the power of Perl, the beauty and elegance of it, but everything was ruined by the absolute shit show when it comes to its packet managers. /rant.

I notice you did not provide any details, depriving us of the ability to determine whether the shit show is PEBCAK or genuine.

Re: Four features that justify a new Unix shell

#146
post #124

Earlier quoted context omitted.

If I've not wildly misunderstood what you're doing with that line (and apologies if I have), could you not just stick `-printf '%f\n'` on the end of the `find` command? (By definition, since you're looking for `.ogg` files, everything `find` finds will have a path that ends in a three letter extension.)

Ah, that is a good one! I've never even messed with the -prinf options.

It's one of those things that's immensely helpful but difficult to discover organically, I think, since a lot of people will go "find outputs this, now I pipeline to transform that, this is The Unix Way" and never realise that `find` can do a bunch of transforms for you for free.

Re: Four features that justify a new Unix shell

#147
post #138

Earlier quoted context omitted.

> I'm sorry to say to for me, shell scripting has lost. All my scripts are written in Python, which a thin shell script wrapper to launch it. I've seen, and still see, plenty of Python scripts launched by a shell script. 9 out of 10 times, Python just causes more problems than it solves, and problems that are trivial to solve with plain old shell scripts. The only reason Python "won" is because we see a constant infl…

This is ridiculous. Python won scripting because it offers a sane way to do sequential, shell-ish things, without having to wade through "man bash" or searching stack overflow for the umpteenth time about the syntax to do something that should be trivial but is anything but. Saying that younger devs only know python is like a FORTRAN engineer in the 90s saying young devs only know java. No one needs to apologize for…

> This is ridiculous. Python won scripting because it offers a sane way to do sequential, shell-ish things, without having to wade through "man bash" or searching stack overflow for the umpteenth time about the syntax to do something that should be trivial but is anything but.

You've inadvertently supported exactly my point.

You just advocate for the lazy way out. You know Python, so that's what you use and nothing more. God forbid you check out a reference. I mean, your lazyness leads you to believe that having docs.python.com on speed dial for a dozen different major or backwards incompatible releases is ok, but oh God forbid you check up a single man page of a tool that exists since the beginning of time.

Ridiculous, and all of this just because you believe you know Python, and that's all you have to offer.

Shell scripts are standard, omnipresent, reliable, and readily available infrastructure. There's no way around it. There's no excuse, let alone laziness and refusal to learn, which in this field is outright incompetence. The only reason someone refuses to use shell scripts for this sort of job is dereliction of duty and outright incompetence, and that is not winning in anyone's books.

Re: Four features that justify a new Unix shell

#148
post #93

Earlier quoted context omitted.

Python has a REPL but it isn't sufficient to be a shell. Therefore, I can't write a program in the Python REPL just as I'm doing stuff normally and copy it into a file for further editing and polishing. I have to port whatever I did in the shell to whatever other language I'm using, which is more porting than I want to do for most shell scripts, especially ones which are mostly pipelines. Heck, Python isn't even a go…

How is python not a good language for one liners? One liners are literally the pythonic way.

By one-liners I meant things like Perl one-liners:

    perl -pe 's{([^}{\1}g'  out.html
Python would never let you get away with treating it like an improved sed.

Re: Four features that justify a new Unix shell

#149

Is this shell actually written in python2 in the year 2020? (see: https://github.com/oilshell/oil/tree/master/Python-2.7.13 )

Some fun idiosyncrasy going on

> It's written in Python, so the code is short and easy to change. But we automatically translate it to C++ with custom tools, to make it fast and small. The deployed executable doesn't depend on Python.

Love it ;)

Re: Four features that justify a new Unix shell

#150
post #110

Earlier quoted context omitted.

Feel free to demonstrate. Take a long path with nasty characters and give me the ending file name. I want "track1.mp3" returned from: /podcast/with/nasty'--c h a r$/and/stuff/track1.mp3

If you have that in a variable, which you presumably would if you're reading them one at a time, you can use "remove longest matching prefix" substitution. $ i="/podcast/with/nasty'--c h a r$/and/stuff/track1.mp3" $ echo "${i##*/}" track1.mp3 [Edit: 'thezilch beat me too it by a couple of minutes]

You still get +1 for providing a pointer to the explanation while remaining clear and succinct.
Post reply on HN