Interesting article, though for me an acceptable middle ground is to just use bash and friends as an interface, as described, and to write any larger and more complicated scripts in Python with argparse (or similar).
I don’t see why the shell must be both nice to program in and a concise textual interface.
Shell scripts are the automation and extension of repetitive, tedious manual tasks. Why wouldn't you want to take your shell history and wrap it in some getopt-ish stuff? Or to put it another way, why would you wish to throw away your debugged and working code for a rewrite in another language?
You're missing a step. You originally wrote "I don’t see why the shell must be both nice to program in and a concise textual interface."
I attempted to demonstrate how evolving a CLI session into a script is very beneficial. That bash is not great for that purpose is exactly the point of the article. A better shell language would mean not throwing away your organic, working code for a rewrite.
Unless you're trying to say that you rarely use the command line to explore a system and operate mostly through scripts. I think I would burn a lot of time in writing boiler plate when "curl | grep" would do the job for human consumption in less than 50 keystrokes.
I see what you mean now. I still draw the line differently - I don’t think I’ve ever interactively worked through conditional logic, control loops, or user prompts, so I’d happily make simple bash scripts from basic commands, but I wouldn’t choose to write more complex programs that way.
> I don’t see why the shell must be both nice to program in and a concise textual interface.
Because people just want to have one consistent tooling for everything, and it should be effortless available everywhere. Especially portability is a huge problem.
bash is a horrible interface though. Teleprinter compatibility is a bit too much to bear today and really gets in the way, at least for me. On the other hand, I can happily live without all the cool arcane bash features that have crept in over the decades.
Downloaded murex to try it out. It was really janky, unusually so, with red colored text that is difficult to see on a black console. Requires libpthreads. Interesting first impressions. I will be dead before anything like this ever replaces the Bourne shell. There is little incentive to switch and lots of incentive to continue toward mastery of the ubiquitous shell, the one I have to use on POSIX-like OS, on computers of all sizes, like it or not.
> with red colored text that is difficult to see on a black console.
Thanks for your honest feedback. It's only errors that appear in red and you can disable that feature if you want[1]. However it's pretty standard these days for DevOps tools to output errors in red but I appreciate that is still not to everyone's tastes.
It should also be noted that I'm honouring the terminal emulators colour palette. So if a colour isn't readable then it's the terminal emulator you're running that has caused that issue. Personally I recommend the Solarized colour themes because all 16 colours are equally readable but your preferences might differ.
> There is little incentive to switch and lots of incentive to continue toward mastery of the ubiquitous shell, the one I have to use on POSIX-like OS, on computer of all sizes, like it or not.
I do get that sentiment but more and more these days most of the console work is done on your local machine and you rarely SSH onto remote hosts (some orgs even go as far as to disable SSH access entirely since everything should be managed via Ansible/Puppet/Chef/SSM/etc). The problem murex attempts to solve is to be a better shell for local development / DevOps tooling. There's no point trying to get murex pushed as a default shell on servers because no security team would authorise it. But for local tooling there are still a lot of gains to be made.
This is why you'll see features like errors highlighted in red and spelling errors underlined. murex takes as many cues from IDEs (local development) as it does from POSIX-shells.
It's cool project it's just not for me. I am too comfortable with a basic Bourne shell, VGA textmode, no UTF-8, TERM=vt100. If it were possible to "improve" on this basic environment, I would want the new shell to be something less, not more; simpler, not more complex. Anyway, ignore the negative feedback. I am not the target audience for murex.
I have used Fish before, though we are talking 10-ish years ago, and there is a lot to like about it. However it didn't resonate with me personally. I guess you could describe my feelings towards it as sort of an "uncanny valley" where it was too different to Bash to be compatible while being too similar to Bash to be worth the effort learning. So the whole experience felt more jarring than enlightening. Again, this is just a personal feeling and not a comment on their technical accomplishments. For example I was always impressed by just how polished Fish's interactive shell is.
When designing murex (the shell I now use daily) I wanted to go one step further and say "If I'm abandoning Bash compatibility then what new things can I bring to the table". This will no doubt alienate a lot of new users that might prefer Fish's "like Bash but better" approach though. Which is fine, there's more than enough room for both shells to exist.
Obviously, syntax preferences in programming languages are very personal, so what someone considers to be simple and beautiful, someone else may consider as complex and ugly.
Nevertheless, in my opinion, the right way to improve the "if ... fi" POSIX shell syntax is not by adding tons of superfluous curly braces, but by removing the redundant square brackets and the redundant semicolon (all of which have historical reasons for their presence).
With those changes, you have the minimal fully-bracketed syntax for a conditional statement, e.g. (if ... then ... elif ... then ... else ... fi).
If you do not like these keywords, that is fine, you should replace them with other keywords or symbols.
For example, I like concise syntax, so I replace those keywords with certain Unicode symbols, i.e. mathematical angular brackets instead of if and fi, section sign instead of elif and else, and left arrow instead of then.
It does not matter what keywords or symbols you like, but both the ease of writing and the ease of reading are improved when each kind of program control structure uses distinct delimiters, not just the same curly braces for everything, and also when there are no redundant delimiters, e.g. in C and derived languages there are a very large number of redundant parentheses, which are needed because the curly braces are optional. Had the curly braces been mandatory in C, the parentheses from if, switch, while, for would have been deleted, which would have lead to easier to read and write programs in the common case, when braces are used.
The final syntax presented has an almost double number of delimiters than needed, presumably because the curly braces are reused for various other purposes in the complete murex shell syntax.
Trying to use too few distinct symbols or keywords is guaranteed to increase the number of redundant delimiters.
Maybe the Algol 68 method of inventing keywords like fi, esac, od, was not the most inspired, but the principle of using different kinds of delimiters for each distinct purpose was, and is, sound.
I agree to an extend and in fact this is what murex already does. Superficially it looks like C (minus semi-colons) but the parentheses are the tokens that replace the ALGOL style then, else and fi keywords. What murex does do is allow those keywords to be optionally included for readability. So all the docs will say
if { = 1==2 } then {
err 'math is broken'
} else {
out 'math works'
}
as it's easy to read but really the then and else keywords are just ignored. So the same one liner is perfectly valid
if{= 1==2} {err 'math is broken'} {out 'math works'}
So you do have the terseness in the interactive shell that you're requesting.
The curly braces do serve an important significance to the parser in murex. Because everything is defined as a function, it means `if` is a builtin and the curly braces are read like quotation marks denoting the start and end of executable parameters (like a subshell but minus the forking). So the `if` command gets the arguments passed like so (pseudo-JSON):
> if{= 1==2} {err 'math is broken'} {out 'math works'}
So you ended up with kind of like TCL's choices (`then`, `else`, `elseif` are optional; prefix expressions with `=` (`expr` in TCL's case, although it's implied in `if`, `while` conditionals) )
Great answer!, and… well, I’m adding it to the article. In my head :)
My experience with fish is quite different, and that’s exactly why I find this discussion so good.
Regarding how shells are made more than the shells themselves, I wish to point to the design document itself in case you haven’t had the chance to read it yet; It’s one of the better texts on this sort of thing. I’d be interested in your take on it if one is available :)
I like the layout of the design document and I might steal this page idea myself. However I don't agree with all of the contents:
> The law of orthogonality
For better or for worse I went the other way and crammed murex full of builtins. Most builtins are single purpose too.
Rational: while it creates additional work learning murex it does make pipeline more descriptive
> The law of responsiveness
This I do agree with an murex does a lot of tasks asynchronously for exactly the same reasons too
> Configurability is the root of all evil
I actually don't disagree with their point on principle but I think a better stance should be "Defaults should not leave most users itching for configurability" because I think configurability is a good thing however a product should ship already configured so that users aren't left having to enable features they want.
The early versions of murex came with features turned off so it behaved a lot more like Bash. Then I realised nobody is going to enable spellchecking, syntax highlighting, etc because nobody is going to know it is there. So now most features are enabled by default.
> The law of user focus
The description I agree with, the examples I do not. You don't need to remove features to make something user focused. You just need to make those features usable and discoverable.
"Microsoft had the benefit of being able to start from a clean room. They didn't need to inherit 50+ years of UNIX legacy when they wrote Powershell. So their approach was naturally to base their shell on .NET."
The POSIX shell had a specific requirement: when compiled, it had to fit within the Xenix 64k text segment.
This is something that Powershell will never, ever do.
Gauche scheme is a very "scripting-focussed" implementation, with some niceties inspired from scsh. I've used it's repl as a shell of sorts for a short while, just to see if I could.
Janet is a new lisp (heavily inspired by Lua, not surprising given its author had previously started fennel, a lisp which compiles to Lua) which fits a smiliar "scripting" niche. An extension has been made for it (janetsh) to make it suitable as a shell replacement.
In a similar vein, racket has rash.
And if you consider tcl as a "lisp for strings", then it's almost a shell right out of the box. I've used jimtcl (again, like gauche, with a heavily customised shell-focussed lib of my own) as an interactive shell.
Lot's of choices out there, if one is willing to roll one's sleeves up ;-)
Actually there exists a shell, "scsh", which uses the Scheme language, i.e. a LISP variant.
"scsh" is less convenient for interactive use than bash or zsh, because it is more verbose, but it was quite good for scripts, certainly more convenient as a replacement for shell scripts than Python or the like (because it had a better syntax for the equivalent of a POSIX command list, with pipes, and/or lists, redirections and parameter expansions).
Many years ago, I have written and used with good results a lot of "scsh" scripts, for things deemed to be too complex for POSIX shell scripts.
However, AFAIK, "scsh" has not been updated in recent years, so I do not know how good it would still be today.
Murex comes across kinda lisp-y with the keyword-less, prefix-notation #'if statement. Emacs also offers a unique (and very lisp-y) shell syntax within #'eshell.
I don’t see why the shell must be both nice to program in and a concise textual interface.