A Second Search for Bash Scripting Alternatives
The author explores modern alternatives to Bash scripting for embedded systems, evaluating languages like Elvish and Nushell based on criteria such as arrays and external program calls, while documenting their experiences.
Read original articleThe article discusses the author's exploration of alternatives to Bash scripting, particularly in the context of embedded systems. The author reflects on their previous search for Bash replacements, which included languages like scsh, luash, and mruby. With a shift in their work focus from embedded devices to higher-level programming languages such as JavaScript, Python, and C#, the author has returned to the embedded domain and is seeking modern scripting alternatives. The post outlines the criteria for a suitable scripting language, emphasizing the need for features like proper arrays, dictionaries, and the ability to call external programs. The author plans to implement a sample script across various languages to evaluate their usability and performance. The languages under consideration include Elvish, Murex, Ion, Nushell, and several others, with some being rejected due to high memory requirements or lack of documentation. The author acknowledges the challenges of learning new languages and aims to document their experiences, including any difficulties encountered. The exploration is ongoing, with the potential for future candidates to be evaluated.
- The author is searching for modern alternatives to Bash scripting for embedded systems.
- Criteria for suitable scripting languages include support for arrays, dictionaries, and external program calls.
- The author plans to implement a sample script in various languages to assess their usability.
- Some languages have been rejected due to high memory usage or insufficient documentation.
- The exploration of alternatives is ongoing, with the possibility of future candidates being considered.
Related
Ruby: A great language for shell scripts
Ruby is praised for shell scripting due to its features like calling external commands, handling status codes, using types, functional constructs, regex matching, threading, and file operations. It's recommended for complex scripts alongside Bash.
I Probably Hate Writing Code in Your Favorite Language
The author critiques popular programming languages like Python and Java, favoring Elixir and Haskell for immutability and functional programming benefits. They emphasize personal language preferences for hobby projects, not sparking conflict.
Metaprogramming in Bash
Adam Young's blog post on metaprogramming in Bash emphasizes efficient scripting for managing multiple machines, advocating for reusable functions, dynamic variable assignment, and potential Ansible integration for improved automation.
Shell Has a Forth-Like Quality (2017)
The blog post compares the Unix shell's Forth-like qualities and higher-order programming with systemd's role in Linux boot processes, advocating for an improved shell while favoring daemontools' modular design.
A tiny self-remaking C program
The article introduces a self-rebuilding C program using a minimal shell script, emphasizing the build process as computation, the importance of caching, and the need for improved security scrutiny in build systems.
1. Bash (or ysh, which I do prefer but isn't as available)
2. Python, using the `sh` package as needed. It's been great for upgrading shell scripts, and `sh` is really nice to use.
3. Rust, usually. That's my personal language of choice for "real" projects.
I have a number of projects at each stage actually, though most of the things I'd call a real "project" with it's own repo end up as Rust projects.
That being said, if you are doing something other than just piping together processes and managing unstructured streams of flat plaintext, bash is the wrong tool for the job. bash is best used interactively, in the REPL, for having a back-and-forth conversation with the machine and interrogating its current state (filesystem, resource usage...), or that of other machines over the network (that is, using dig, curl, openssl, ping, mtr, etc), and processing streams of text. Even for lightly structured data, like if I am doing boring, garbage CRUDdy tedium on the web and need to figure out how to do some rudimentary transform of a JSON document, figure out which headers to send and which endpoints to hit, curl and jq it is - and there I am, reshaping the data in as interactive of an environment it gets.
The minute I need to write something for a non-interactive, end-user use case, with requirements for better domain modelling / structuring of data, testing, deployment, readability, maintainability, extensibility, etc. it is time to reach for a more modern language. But if you want to talk to the machine, virtually any (non-Windows) machine, interactively, bash is your lingua franca, or perhaps your Latin/Ancient Greek/Aramaic, esoteric and outdated as it is.
I also get the feeling that people just recoil at any level of complexity and need to hide behind their clean, simple abstractions these days. As a Haskell enthusiast, I am also susceptible to this tendency, but one needs to be at least capable of diving into the historical, messy work underneath the hood.
Bash shell scripting is already close to perfect for what it is intended. Where people always complain is one of three areas: 1) "footguns", 2) "not enough features", 3) "not a programming language", 4) inexperience.
1) is almost entirely due to it being a programming-like language bolted onto an interactive console terminal. Bash has a lot of changes over vanilla Bourne/Posix that make it less console-y and more programming-y. But if you take away the interactive-terminal-ness itself, then you don't need most of the Bashisms.
2) is almost always a mistake. Bash has pretty much all the features you need. But again, it's hampered by the interactive-terminal-ness; take that away, and you can do pretty much anything, with ease.
3) is because programmers don't understand what scripts are for. They are not for writing robust programs. They are for solving a small problem, in a specific, tailored way, with the least amount of effort and time. This means that you should be abandoning all of the programmer's best practices and rules. Throw out safety, reliability, consistency, verifiability, etc. What you end up with is a solution that works, with nothing extra.
4) comes when people simply don't know how to use Bash very well, which is 90% of the time. Ever since I became a programmer two decades ago, the great unwashed masses of techno-dweebs who call themselves "programmers" have been picking up complex and nuanced technology that they have never bother to formally learn, and then complain that it sucks and they need an alternative. When in reality, the problem is almost always either a) they didn't read the manual, b) they haven't practiced using it, or c) they're using the wrong tool anyway.
Doesn't matter if you disagree with me. We will be using the same shell scripts in 20 years. Know why? Because you can't make it any simpler, and it just works. Complain all you want about it not being perfect. You simply will not be able to make something better without simultaneously making it worse. Its killer feature is its lack of features and design. It is the anti-programming language. And boy do I love it.
Perl was made to solve precisely these kind of problems.
Just use Perl. Its fast, matured, has CPAN and is dedicated to maintaining backwards compatibility for years to come. Using anything else will not make all that much sense. You will be reinventing a whole universe(and badly from scratch). And achieve nothing at the end.
Been happily using it since 2018. It's great not to have to learn a whole other language just to do scripting.
Long way to go but was very happy to see someone wanting a better alternative to bash and trying ABS out!
LOL, so true
Im exicted about cargo-script (rust). hopefully soon.
Related
Ruby: A great language for shell scripts
Ruby is praised for shell scripting due to its features like calling external commands, handling status codes, using types, functional constructs, regex matching, threading, and file operations. It's recommended for complex scripts alongside Bash.
I Probably Hate Writing Code in Your Favorite Language
The author critiques popular programming languages like Python and Java, favoring Elixir and Haskell for immutability and functional programming benefits. They emphasize personal language preferences for hobby projects, not sparking conflict.
Metaprogramming in Bash
Adam Young's blog post on metaprogramming in Bash emphasizes efficient scripting for managing multiple machines, advocating for reusable functions, dynamic variable assignment, and potential Ansible integration for improved automation.
Shell Has a Forth-Like Quality (2017)
The blog post compares the Unix shell's Forth-like qualities and higher-order programming with systemd's role in Linux boot processes, advocating for an improved shell while favoring daemontools' modular design.
A tiny self-remaking C program
The article introduces a self-rebuilding C program using a minimal shell script, emphasizing the build process as computation, the importance of caching, and the need for improved security scrutiny in build systems.