Live data from Hacker News

Hush, a modern shell scripting language

hush-shell.github.io

141–150 of 192 posts

Re: Hush, a modern shell scripting language

#141

Earlier quoted context omitted.

> it's more unix than unix. Would you please elaborate what exactly do you mean by this?

Powershell improves on Unix commands being based on text streams, and makes them based on objects. Which means you're pretty much never extracting stuff with cut and awk, and instead can just get whatever field you want. Eg: C:\Windows> Get-AuthenticodeSignature .\explorer.exe Directory: C:\Windows SignerCertificate Status StatusMessage Path ----------------- ------ ------------- ---- BBD2C438000344F439BFDFE5ABAC3223…

> Isn't that awesome?

It depends. In a world where commands produce, expect and consume well defined and highly structured data streams, it is actually great. It works well in Windows but only because scripting as the concept is relatively new to the Windows world.

In UNIX, however, it is usually a mess and data extraction using the PowerShell approach would almost never work due spurious characters appearing in the output of a command (for any reason, really) as the UNIX style is precisely this: «cobble things together, use a sledgehammer to make everything work and move on. If it ain't broken then don't fix it». This is why running the output through a «sed» and searching for stable string patterns to cut interesting parts out and then (optionally) running them through cut/awk/et al is the Swiss army knife.

Life has become somewhat easier recently with the advent and more widespread use of JSON, YAML (and to a certain extent XML before) as we now have jq, yq, dasel, mlr (Miller), xmlto etc – to capture, for instance, the JSON formatted output and do something with it just in the same way it is possible in PowerShell whilst also retaining the extensibility (see below) without having to rely on the availability of the source code of the producing utility/app.

> One of the nice things about it is that you can add stuff easily. You don't have to worry that every script that parses the output of your command will now break because you added an extra column or added extra functionality.

You can only add stuff easily if you control (own) the producer of the data stream. If the producer is a third party provided script/app you don't have the source code for, I believe you still have the same breakage problem, however PowerShell experts might want to chime in and correct me.

Re: Hush, a modern shell scripting language

#142

> Traditional shell scripting languages are notoriously limited I feel like people looking to replace shells and shell languages need to really think deep and hard about this if it's something they believe. Shell scripts are really anything but limited, and in fact most replacements are more limited (either by design or by accident), often imposing awkward control flow on you or making things that should be simple mu…

The weakness of the shell is that it did not emerge as an LR-parsed language that could easily be expressed with a concise yacc grammar. The "one true awk," for example, bundled a yacc grammar as part of the build until relatively recently. The complex grammar of the POSIX shell is ambiguous in the extreme in many situations.

The shell language was further constrained by POSIX that removed much Korn shell functionality, even though a public domain implementation of Korn existed. This was done to allow the shell parser to be very small, and Debian's Almquist shell compiles to under 100k on i386 (unlike bash, which trails it also in speed).

This new Hush shell looks a bit too wordy and reminiscent of javascript.

Anyone designing a new shell grammar should also design in such a way that Busybox could bundle this new interpreter, should popularity justify it.

Re: Hush, a modern shell scripting language

#143
post #60

Earlier quoted context omitted.

> The first two lines are pure overhead. In 200 bytes half of which is overhead. That's not a great start. > The last line is the equivalent of a shell script one liner It's slower and requires much much more typing, and anything I want to add isn't going to go in the right place. It has a gross hack to support "tmux", and produces other spurious output (bugs). I don't want my X sessions or other ptys; I have reverse…

for those of us with not as much grey in our beards (+1 this response if you get the joke) the python example is a ton more readable to me. Now that probably doesn't matter if the utility is only for you. I've a number of helper programs/scripts/etc that I use that I wrote and are only for my consumption. Re the paralell stuff and python it's easy to import multiprocessing and take advantage of all cores. I think whe…

> the python example is a ton more readable to me.

The python example is also wrong, as in it produces the wrong output: Maybe if you are only worried about your own consumption you can ignore all those poor souls running literally any other application besides ssh and tmux, but at some point you're going to have to stop admiring how "readable" it is and fix it, and then what?

I don't buy that conservative coder mentality of keeping the code clean and readable, because one drop of shit is going to be impossible to remove later. In fact, I think that's bananas. Get correct first, then improve.

> Re the paralell stuff and python it's easy to import multiprocessing and take advantage of all cores

You jest.

> I think where python wins is how easy it is to handle errors

Pray tell what errors do you think we need to handle?

Re: Hush, a modern shell scripting language

#144
post #14

The language looks really quite interesting. I could see myself using it for quick scripts. I think I'd prefer bash's noclobber behaviour to be the default redirection style. The explicitness of being forced to >| always feels like a nice safety feature to me, which would tie in nicely with their other defaults for safer scripting. Also, not sure I'm keen on their minor change to the redirection syntax¹. It suggests…

attacking the problem of improving shell scripting while attempting to keep the syntax

(Oil author here) Slight correction, The project has two parts

(1) OSH (bin/osh) will run your existing scripts, so in that sense it does keep the syntax

(2) The Oil language (bin/oil) is an upgrade from OSH, but it can also be thought of as a clean slate language:

https://www.oilshell.org/release/latest/doc/oil-language-tou...

It's really the same interpreter with a few parse time and runtime options. There were surprisingly few compromises (probably the biggest one is the shell-like string literal syntax, which I mention.)

The biggest changes are that we take over ( ) and { } , so you can write stuff like:

    if (x > 0) {
      echo 'positive' | tac
    }
Rather than

    if test "$x" -gt 0; then
      echo 'positive' | tac
    fi

We add a Python-like expression language between () and surprisingly few things need to change to make it feel like a "new language".

Thanks for mentioning Oil :)

Re: Hush, a modern shell scripting language

#145
post #82
post #14

The language looks really quite interesting. I could see myself using it for quick scripts. I think I'd prefer bash's noclobber behaviour to be the default redirection style. The explicitness of being forced to >| always feels like a nice safety feature to me, which would tie in nicely with their other defaults for safer scripting. Also, not sure I'm keen on their minor change to the redirection syntax¹. It suggests…

> It suggests that "2>1" and "2> 1" have very different results FYI, "2>1" and "2 >1" already have very different results in Bourne shell. So I don't think it's an unforgivable sin.

Yeah this is the crazy thing about shell redirect syntax

   2>&1   # descriptor redirect

   2>& 1  # identical to above

   2 >&1  # runs a command "2" and then does a descriptor redirect
And likewise for

   2>1
   2> 1
   2 >1
The 2 is really part of the operator, but the 1 isn't !

Re: Hush, a modern shell scripting language

#147
post #142

> Traditional shell scripting languages are notoriously limited I feel like people looking to replace shells and shell languages need to really think deep and hard about this if it's something they believe. Shell scripts are really anything but limited, and in fact most replacements are more limited (either by design or by accident), often imposing awkward control flow on you or making things that should be simple mu…

The weakness of the shell is that it did not emerge as an LR-parsed language that could easily be expressed with a concise yacc grammar. The "one true awk," for example, bundled a yacc grammar as part of the build until relatively recently. The complex grammar of the POSIX shell is ambiguous in the extreme in many situations. The shell language was further constrained by POSIX that removed much Korn shell functionali…

While being extremely small is a worthy goal, I suppose the aim of Hush is to make writing larger shell scripts easier and less error-prone. It's more for the niche of Perl of old than of minimal shells like ash.

For a very limited device, a very limited shell like that in Busybox is sufficient, because it likely does not need large shell scripts, or a lot of interactive work.

Looking at [1], current Hush is under 700k, which is still way smaller than Python or Perl, with much of its expressiveness.

[1]: https://github.com/hush-shell/hush/releases

Re: Hush, a modern shell scripting language

#148

> Traditional shell scripting languages are notoriously limited I feel like people looking to replace shells and shell languages need to really think deep and hard about this if it's something they believe. Shell scripts are really anything but limited, and in fact most replacements are more limited (either by design or by accident), often imposing awkward control flow on you or making things that should be simple mu…

Yes, exactly. I have a few slogans for this, but one is that the shell language should compose with the rest of the operating system, which is "processes and files". It's a situated language.

So I have been making the point that the "narrow waist" of shell is still processes and files. Whereas the narrow waist of Python and Lua is functions and compound data structures like dicts/lists (tables).

One thing that is not quite obvious until you design AND USE a shell language is that if you have these conflicting narrow waists, you have problems of composition, and you will offload this complexity onto your users.

From a very quick look at the hush docs, it is Lua with some shell-like stuff grafted on. I believe that will cause cause such problems in programs. They will be longer and harder to write. You will have more edge cases.

----

I hit this issue many times in Oil, and I wrote many posts tagged #software-architecture about it:

http://www.oilshell.org/blog/tags.html?tag=software-architec...

Unix Shell: Philosophy, Design, and FAQs http://www.oilshell.org/blog/2021/01/philosophy-design.html

makes several of these points.

This recent post

http://www.oilshell.org/blog/2022/03/backlog-arch.html

asks:

    - Should shells have two tiers?
      - Both external processes and internal "functions"? 
      - Both pipelines of bytes and pipelines of structured data?
    - Another one I'm working on now: Both exit codes and Python-like exceptions?
In Oil the answer is yes for the first 2, but a subtle point is that the former are PRIMARY and still the narrow waist; the latter are helpers. Dicts and Lists exist to help you deal with files (and produce JSON and TSV); but they're not the primary structures of the program.

I've also discussed this issue pretty extensively with the authors of the NGS and Elvish shells.

A related recent comment: https://old.reddit.com/r/ProgrammingLanguages/comments/ub5vi...

Having unsigned / signed and sync / async (what color is your function?) are similar problems of composition in language design. I call them "Perlis-Thompson" problems.

There is no easy answer but IMO it's vital to explicitly think about and address these problems. C has a flawed solution to the combinatorial explosion (implicit conversions), and it's caused problems and been lamented for ~50 years. There's also a good quote in that thread about why unsigned sizes in STL were a language design mistake.

Re: Hush, a modern shell scripting language

#149

Earlier quoted context omitted.

> We need better shells. Obviously. I don't think this is the most important missing part, though. I would say it differently: we need way, way better REPLs. IPython is an example of a REPL that's passable as a shell. It can run in a terminal and has a GUI version based on Qt, which allows displaying images inline. You can drop into a "real" shell with a single `!` character (you get pipes, output capture, and (Pytho…

The REPL is the shell. I even used the term "REPL" (and a couple of synonyms too) in my comment. So I do agree it's critical but that doesn't make the language irrelevant. Your point about how Python shells have had to create syntactic sugar for REPl usage is a good illustration of my point about how it matters a lot. Also you can render images in quite a few terminal emulators already. Some shells (mine included) sh…

REPLs are highly interactive. Shells are also needed to run scripts.

A Bourne shell implementation without Readline is a pain to use as a REPL, but is a completely adequate shell scripting tool.

Re: Hush, a modern shell scripting language

#150
Folks interested in this design space may enjoy reading about scsh (A Scheme Shell)

From the scsh paper (https://web.archive.org/web/20081010222846/http://www.scsh.n...):

> I have designed and implemented a Unix shell called scsh that is embedded inside Scheme. I had the following design goals and non-goals:

> The general systems architecture of Unix is cooperating computational agents that are realised as processes running in separate, protected address spaces, communicating via byte streams. The point of a shell language is to act as the glue to connect up these computational agents. That is the goal of scsh. I resisted the temptation to delve into other programming models. Perhaps cooperating lightweight threads communicating through shared memory is a better way to live, but it is not Unix. The goal here was not to come up with a better systems architecture, but simply to provide a better way to drive Unix. {Note Agenda}

> I wanted a programming language, not a command language, and I was unwilling to compromise the quality of the programming language to make it a better command language. I was not trying to replace use of the shell as an interactive command language. I was trying to provide a better alternative for writing shell scripts. So I did not focus on issues that might be important for a command language, such as job control, command history, or command-line editing. There are no write-only notational conveniences. I made no effort to hide the base Scheme syntax, even though an interactive user might find all the necessary parentheses irritating. (However, see section 12.)

> I wanted the result to fit naturally within Scheme. For example, this ruled out complex non-standard control-flow paradigms, such as awk's or sed's.

Post reply on HN