-- Leo's gemini proxy

-- Connecting to warmedal.se:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini; lang=en

Why I Use Bash


Stacksmith wrote about "Misadventures with bash shell" and asked which shells others use and what we love about them.


Well... I use bash. I'm sufficiently well-versed in bash to sit through a full day of it at a Red Hat System Engineer course and not only not learn anything, but knowing when the instructor is wrong.


But do I love bash?


Not really, I guess. I've used it for a very long time and know its strengths and weaknesses. I usually know how to get things done with it, and most of all when it is or isn't suitable for a specific situation.


The big advantage with bash is that it's available everywhere, more or less. And I hate having to configure or install stuff to be able to use a new system. When inheriting a server from a previous sysadmin there will always be a lot of tools written in bash as well which makes it essential to understand it.


In all these years of using it there's been a few key learnings that really deepened my understanding of it.


The reason whitespace matters is because [ and [[ are not just parenthesis but programs that return true or false. Thus [[blah is a program that (probably) doesn't exist, but [[ blah is a call to [[ with the argument blah.

The difference between $* and $@. The first expands all arguments into a single string, but the latter is an array! When quoting ("$*" and "$@" respectively) the arguments "I" "say" "Hello World!" will expand to "I say Hello World!" with the first option but a list of three arguments "I" "say" "Hello World!" with the second one.

$arg is the legacy version of ${arg}. There's no real difference but when for example prepending an argument to a string $arg_string attempts to evaluate the variable arg_string whereas ${arg}_string behaves as expected. Similar with `command` which is the legacy version of $(command). The latter is just a better and clearer syntax.


There is an argument to be made for using a shell language instead of a "proper" programming language. Very often you just need to run a few different programs and get the output or exit codes from them, and that's a magnitude simpler to do in a shell script than having to invoke exec functions and pipe reading in most programming languages.


On another note I really want to learn Lisp, but oh my god the horrible mess of nested parenthesis...


-- CC0 ew0k, 2022-08-02

-- Response ended

-- Page fetched on Sat May 4 15:36:02 2024