Shell Languages and the Linearization of Syntax

By Xah Lee. Date: .

Shell Languages and the Linearization of Syntax

Now let me explain, xah monolog, on what is shell, its design elements.

First of all, what is a shell. Typically, it refers to the command line shell. e.g. unix bash. Most well known. Sometimes, it also refers to a 'graphical shell'. Typically, a windowing system, or desktop aka gnome, are graphical shells.

In general, a shell is defined to be something that lets one interface with the os. That sense, is kind lose and old. Shell, originally, is just a command line to os. And 40 years ago, unix shell, are exactly, an interface to the os. Anything u do with os, is done by command. Not so today. Lots things u do with os today, u cannot do with command line. And the concept of graphical shell, doesn't mean much of anything, because it just became synonymous to a gui. Mostly, the graphical shell meaning become more of a skin thing.

But, let's take the classic definition of shell. Namely, command line interface to os, and just the things that bash do, as today's bash and powershell.

Now, there r 2 elements to designing a shell.

The basic operations with os, may be called the semantic part of the shell. In unix sh, we have things such as, ls, cat, grep, find, which, who, w, finger, cp, mv, touch, mkdir, rm, fsck, message, etc. And ps, kill, fg, type etc. These are the “semantic” part. Namely, they are the things you need a shell to do. So, in designing a shell lang, you need this. U need to figure out what command, or action, that a user need to do or be able to do with os, with your shell lang.

The second element of shell, is a linearized syntax. Linearized syntax, means, any nested syntax must be reduced to a minimum. Nested syntax means any of the typical parent, bracket, braces, or begin end. Anything that constitute nesting semantically. The most extreme case of nested syntax, is lisp. And other langs, such as c java js, also are filled with them. e.g. function call f(), operator stickiness specifier (), block {}, array []. (and in bash, the if fi idiocy)

you don't want nesting syntax in shell, because, with nested syntax, think of lisp, it makes it very hard to edit or add code in real time. Because it requires user to go to particular position to modify or add code.

I haven't had a thorough study on the linearization of syntax issue. But basically, it's hard to completely eliminate nested syntax (aka matchfix). In particular, is the question whether your lang allow nested array or list or block. Nested array is extremely useful or essential. Kinda impossible to design a syntax that is not nested but allow nested list.

Now, some lang does it. Namely, APL, or RPL. APL i haven't studied in depth. But RPL, aka stack based, uses stack to avoid nested syntax. This is very problematic, because then it requires programer to keep track of what's on the stack. And the RPL syntax, or linear syntax with stack based semantics, is incomprehensible. by the way, the indentation for nesting syntax, e.g. python, is also out. Because it's not a linear syntax, although it rids of nested brackets.

Again, why do we need linearized syntax?

Because, in shell, aka the command line, it's a requirement that the user can construct code, in a sequential, linear, manner. e.g. bash, powershell pretty much do that. Because otherwise, you might just use any lang, such as js, lisp (scsh), python, and write code in a editor and run it. That makes it not a shell lang, because you lose the interactive nature, a important element of shell.

There are not much diff shells. Sh is the original. Then we have csh tcsh sh zsh bash and powershell. And perl, possibly can count, except it doesn't have a interactive interface. The former group, (csh tcsh) (sh zsh bash) are basically the same, some some slight syntax variation and other improvements. Powershell is more drastically diff from the unix ones. Cuz powershell works on object of oop sense with the .net core. While unix shells mostly just process text. But regardless how they work underneath, bash and powershell are in the same syntax design category. Their syntax, is basically just: cmd -opt val ... And with some connective operators such as | & || && > >> < <<

It would be interesting, to see new linearized syntax, eg borrow ideas from apl or functional lang such as ocml.

Unix Shell