logoalt Hacker News

ryandvtoday at 2:17 AM1 replyview on HN

In defense of bash, in spite of its many footguns... you do yourself a disservice if you refuse to learn bash, which is rock-solid stable and has basically ubiquitous deployment. SSH into any server or use any UNIX-like environment and you are instantly at home. While JS and Ruby ecosystems churn every year and mandate yet another round of dependency hell and keeping up with the latest and greatest in rubocop bikeshedding, bash just keeps on ticking throughout the years with little to no recurring maintenance burden.

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.


Replies

chasiltoday at 2:22 AM

The lingua franca is actually the POSIX shell:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...

There is a bunch of bash that you should not learn. The differing coprocess syntax from korn is one particular bugbear. Still, if you are hacking on ReaR or other critical tools that sink deep into bash's slang, you don't have much choice.

show 1 reply