💾 Archived View for malinfreeborn.com › gen › bash.gmi captured on 2022-06-03 at 23:15:00. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-04-28)

➡️ Next capture (2022-07-16)

-=-=-=-=-=-=-

Bash is worse than it needs to be

I love bash, but it's worse than it needs to be.

Earlier today I was updating a script, and had to create lines of text in a file.

It was working fine with echo, and using `\\n` to place a new line into what I made. However, on the server, this stopped working. Same script, same operating system, same updates, same programs installed. However, the local computer was using `dash` as the shell (`/bin/sh`), while the remote was using bash.

So I went with `echo -e`, which should allow `\\n` to be interpreted as a new line. However, while it worked on the server, the local machine just echoed the actual `-e` characters and then the rest. I switched the server to use `dash`, swore quietly at it, then decided to go with `printf` instead of `echo`.

The new `printf` program worked well enough I thought, but the `shellcheck` program told me otherwise - I should *not* be passing variables to it, but should instead tell it that some variable `%s` was there, then place the variable in a separate quote, after the string to be printed.

So instead of

printf "# $header\\n"

I should have printed

printf "# %s\\n" "$header"

This really breaks the conventions I'm used to in bash...but fine. I accepted the wisdom of shellcheck.

Now the line in question had two variables, so off I went to the man page, but printf's man page has no mention of the convention. So off I wandered into the web, on a journey to obtain the luxury of two variables in a single string. Alas, I found nothing, and decided folly was better than spending another minute reading about octal values.

The real problem here is that there is no bash program. It's the gaffa tape that holds other things together, and those things don't play well. I'd like to see the gnu coreutils get a major overhaul personally. I realise this will never happen, because any rewrites will break existing set-ups.

But if I became king of the GNUs, I would happily watch the world burn, just for the sake of having a single command to compose strings, rather than two.