247 karma · joined April 16, 2016
Author of Next Generation Shell.
I am working on another one, Next Generation Shell. We agree on the problem, including that error handling in bash is subpar.
> good programming requires foreseeing and handling errors
I have many small scripts that don't care about errors. Continuing execution in presence of errors is definitely not desirable in these instances, termination is. Ignoring errors is the wrong default for a language, I completely agree with Andy (the author) here. That's why bash has "set -euo pipefail" afterthought. Unfortunately it can't be made the default because of compatibility. Additionally, it has its own quirks.
In general, when judging decades old technologies, I do this check: if somebody was inventing the thing today, what would be the reaction? For bash, many choices made then would be unacceptable today. We know better now. Error handling is one of these choices.
Another related not stellar thing is the exit code of a Unix process. It was supposed to be enough to convey the status of a program. Non-zero is not always an error (think "test" or "grep"), making generic error handling not possible.
These are the decisions that we are paying for.
Thanks!
https://github.com/ngs-lang/ngs/wiki/Hush-vs-NGS
On one hand we are on it since 2013 so there is "more" but I would actually like to highlight the difference in OOP and functional approaches: types, inheritance, multiple dispatch.
good_data = fetch("openlibrary.json").docs.filter({"author_name": Arr, "publish_year":Arr})
good_data.map({{"title": A.title, "author_name": A.author_name[0], "publish_year": A.publish_year[0]}}).group("author_name").mapv(len).sortv((>=)).limit(3)
fetch("cars.json").filter({"color": "red"})
# or
echo(fetch("cars.json").filter({"color": "red"}))
In my probably biased view, NGS is even more domain specific (handling of exit codes, syntax for running+parsing, etc) and more concise.
F fuckoff(x) "lol"
echo(5.fuckoff())
echo("Hello World".fuckoff())Details - https://ilya-sher.org/2018/03/23/google-deleted-our-g-suite/
For scripting, it is significantly better than bash (at least for most of the cases that I have).
The interactive part is not implemented yet but it is planned to be quite different from the dominant decades old approach. The plan is at https://github.com/ngs-lang/ngs/wiki/UI-Design
version_ok = version.split(".").map(Int) >= [3, 6, 8]More NGS perspective on the UI - https://github.com/ngs-lang/ngs/wiki/UI-Design
Things like the above motivated me to create Next Generation Shell.
Edit: hint - yes branch, no branch, exception.
More about motivation: https://ilya-sher.org/2020/10/31/bash-or-python-the-square-p...
Project: https://github.com/ngs-lang/ngs
Disclosure: I'm the author
Project link: https://github.com/ngs-lang/ngs
Enjoy!
Edit: ah.. forgot the whole point.. In Next Generation Shell (author here) this doesn't happen: ngs -e '$(grep ...).not()' does right thing. grep exit code 0 becomes 1, 1 becomes 0, 2 becomes 240 (exception)
Here is my plan for the UI: https://github.com/ngs-lang/ngs/wiki/UI-Design
Edit: but I do try to keep interoperability with existing bullshit.
https://ilya-sher.org/2017/10/10/why-i-have-no-favorite-prog...
Why is this important consideration for you? What's the use case?
Exactly the uses cases that I want to "steal" from Python, Ruby, Perl, etc.
Not because Next Generation Shell is "better" but because it's focused on the use cases - https://github.com/ngs-lang/ngs/wiki/Use-Cases ... while still being a "real" programming language.
Solved. https://github.com/ngs-lang/ngs
I'm the author. Frustrated with exactly this situation I created Next Generation Shell. It's a "proper programming language" on one hand but domain-specific for "DevOps"y scripting on another. So sane syntax, data structures, error handling, multiple dispatch on one hand but also syntax for running external programs, pipes and redirects.
You are welcome!
First and very partial implementation - JavaScript. It was a prototype which I knew I will be throwing away... and I did.
Second attempt, also very partial - Lisp. I used SBCL. Skipping the details here but the result was as follows: got stuck with two different unrelated issues. I did not know would I be stuck with additional issues even if I somehow solve these two.
Third attempt - found a language in which I will never be stuck unable to solve something. C. Also, looked around: bash, Python, Ruby - they are all C. At the time I thought I might be "borrowing" some code from. It didn't happen. I did look though.
Edit: unexpectedly a huge chunk of work, which is garbage collection, was already done for me. C has garbage collection! It is a library - https://en.wikipedia.org/wiki/Boehm_garbage_collector
Author here.
> This seems to be more a simple programming language than a shell.
Currently it's only a programming language. The interactive part will be implemented in the NGS language itself.
> simple programming language
Since simple is relative: NGS is simpler than Java and more complex than awk I would say. NGS has exceptions, types with inheritance, multiple dispatch, guards (additional conditions to invoke a method), basic functional programming support, patterns, (new, in progress) facility for deeply nested data manipulation, automatic parsing of command line arguments when invoking the optional main(), threads, domain-specific syntax and facilities for running external programs and file manipulation.
Simplicity is one of the language goals but not over expressive power.
> A shell is first and foremost a UI, only secondarily a scripting language...
I'm having hard time to agree or disagree. There is a lot of interactive usage but there are also a lot of scripts in bash. When I see the scripts I wish bash was "more of a programming language".
> foremost a UI
... where surprisingly little innovation happened over the last decades. It's like in the movies when there is an object in the center of the screen and the whole world is rapidly changing around it. That object is the shell. My plans for UI are at https://github.com/ngs-lang/ngs/wiki/UI-Design .
> easily take a series of commands you'd do manually and put them in a script
You can do it in NGS and even in this simplest use case it will be better than bash - in case of an error the execution will stop (like with -e in bash) and NGS will print stack trace (which I don't know how to do in bash and not sure it can be done in a sane manner).
Edit: $a will expand to exactly one argument (as opposed to zero or more), rm -rf "$mydir/" will throw exception if mydir is undefined. Typical things which are expected from modern programming languages.
NGS uses small subset of syntax from bash so running external programs in the simple forms looks the same.
Author here. AMA here or in Discord - https://discord.gg/6VqgcpM
cleaning up temp files
Use TmpFile. It is automatically removed when the script exits.
stopping automatically on error
As in many other modern languages, NGS has exceptions and prints stack trace when they are not handled. Nothing special is required from the programmer.
echoing errors
Use built in error("my message") function. Alternatively, use exit("my message") to print the error and exit, the exit code defaults to 1 but can provided. Tired of seeing bash scripts starting with definition of warn(), debug(), error(), etc functions. These are part of standard library in NGS.
You are welcome to check out the Next Generation Shell project.