Or, is there something special that it has? Writing a bash script seems very different to the rest of the programming I do. And not often in a better way.
What are the most interesting, alternatives for simple scripts.
It is very much worth a read.
Besides the idea that command line programs are written primarily for the purpose of being composable, and that they follow a philosophy that makes them easy to work together, I think there are a few other pieces of secret sauce.
The lack of boilerplate is a major advantage. Low boilerplate bash pipes means input/output to/from another program is trivial. Exit code behavior as well as error behavior (output to stderr) further enhances the ease of composing individual tools to do something that would take a while to write a script to do.
The power of bash is that just about anything is trivial if it has the form:
get_data | (map/filter |)* | perform_action
Bash can be an optimal tool for just about anything that does not require "joining" different types of data or "branching" behavior.Once you invoke branching, joining, or complex data structures/formats, bash is no longer the right tool and python is probably the right one (although if ruby had come first, it is actually probably better for relatively simple scripting).
Unix (and later the internet), by enforcing "narrow waists" [1] like a flat stream of octets for all communication, is inherently polyglot. You can have richer data types inside programming languages, and indeed Python, JS, Rust etc. all have vibrant ecosystems of packages with rich internal APIs. But at some point you want to interface software written in widely different languages, and Unix encourages a particular style of command-line interface which is "dumber" — array of arguments, flat file(s) I/O — but is easy to compose across languages.
Therefore, whatever you do in "better" languages, there remains a need for a glue layer whose main job is not doing computation itself but invoking external processes. There is tons of arguing about the threshold — whether a particular task is better expressed inside a "rich" language or by plumbing together commands — but it doesn't change the need for a good shell language to exist.
Now, is bash a great shell language? NO. It's a pragmatic choice for historic reasons. One day we'll do much better. [2]
[1] https://www.oilshell.org/blog/2022/03/backlog-arch.html [2] https://github.com/oilshell/oil/wiki/Alternative-Shells
Exactly.
> [...] And not often in a better way.
Compared to a fully-fledged programming language? I sure hope so.
> What are the most interesting, alternatives for simple scripts.
For simple scripts, there's no better alternative. ZSH has some features that you wouldn't find in bash at the time.
The safest approach is to use bash or shell (/bin/sh). For programming languages golang binaries are portable, that's the big advantage over python, ruby, perl, etc.
When you need to perform advanced error checking, etc. makes sense to use a programming language. For simple operations bash is great, assuming one understands how process ripping works, signal propagation etc. works.
It's a popular "command" language. PowerShell's language is another "command" language, but Bash is more popular than PowerShell due to its vastly longer history and Unix's superiority as a platform for technical work compared to Windows.
Other "scripting" languages (like Python or JavaScript or Ruby) are not drop-in replacements for Bash or PowerShell. You can do with Python what you should do with Bash (such as a nightly system maintenance script or a script that installs a program on your system), but it will be more work (assuming you've already paid the not-insignificant upfront cost to learn Bash). Bash directly interfaces with the system shell in ways Python cannot and was not meant to. Python's a general-purpose scripting language, meant for general work on any system, while Bash was designed to be your gateway to the Bash shell (the terminal) for your Unix system, same as PowerShell for Windows.
Arguably, on the flip side, that's why it's so horrible for general purpose work compared to Python. Making a Space Invaders game in Python? Great. In Bash? Morbidly cool but horrible.
There are Python-based shells for Linux, for example, but I don't think Python can ever be as ergonomic of a "command" language as Bash since they're two different paradigms. They just happen to both output script artifacts.
After a while you will appreciate that the script you wrote 10 years ago still works everywhere, and that new shiny thing that was supposed to replace it died and withered away instead.
I tried Ruby instead and it's nice but not enough of an improvement over bash for me. I tried Julia which has nice support for shell but the JIT compilation was annoying so I dropped it.
Currently I'm trying Nimscript, which is ok but example code is sparse, docs unfriendly, and the language is hostile to tabs and it has noisy output that you have to disable. Overall it's not pretty but workable so far.
Before you downvote me for insulting your fave language, he asked for opinions, and that's what I wrote.
As a contrast I have been experimenting with using Lua and lua-posix to write a wrapper around ffmpeg. Just some batch encoding tasks nothing too complicated. The logic is easy, spawning the main encodes isn't difficult, reading the json output of ffprobe is hard.
Like Bash, Perl is also widely available, more concise and faster than Python, and more of a full programming language than Bash.
People love to 'hate on' Perl, but how many of them have actually used it?
Most Linux and Unix systems include Perl by default and Perl-compatible regular expressions are the defacto default. For quick and dirty, non-Bash scripts Perl is an excellent choice.
Is it -0 --null, -zero or -z?? Who knows? And every app has a different option. Only a grizzled old greybeard would remember.
Things like python, perl, etc are all "nicer" programming languages, but have a lot more issues with distribution. Bash (and related shells) is just a bunch of syntax around setting up environment variables and running commands, which are just executables.
*nix shell is an interactive, concatenative string language with transparent file system access and binary loading capabilities. It's fairly unique among languages and very good at what it does. I would hate to have to write a python script or C program every time I want to rename 1000 files or repack an archive or execute a few programs in sequence or conjuction.
Perl has a reputation, and isn't always available. Python isn't always available either and has the 2 vs 3 problem still (maybe not for much longer).
Many scripts are super simple, or at least start that way, so something that starts as just a list of commands to run is a better interface; but it gets unweildy if you need deeper logic and nesting of things. Such is life.
Much can be accomplished with 1 liners that are easy to type. That can't be done with something like Python.