Things not to do in a shell script 🐚

I parse some news RSS feeds into gemtext

which makes reading news quite pleasant, but sometimes the output is pretty broken. That's because it's done in a humungous pipe of CLI tools, especially sed. It's more surprising that it works most of the time than that it fails. This isn't really a task for shell scripting. When it breaks, it's hard to understand why (beyond "the input isn't what was expected"). I wonder if the sane way to do it would be... XSLT?

I once said "...never since have I had a problem that I wanted to solve with XSLT."

And I wrote a tag crawler

also as a big heap of shell script. I really can't recommend this approach. Things that are broken are a big pain to fix, so I've just lived with some minor but annoying bugs. Again, it's more surprising that it can work than that it's got bugs.

What's the takeaway from this? I think that size may be a good clue as to when it's a good idea to stop using a shell script. "If it's more than n lines, find another way to do it" (for some small value of n).

Why didn't I do that? Because the barrier to entry to writing a shell script is almost nothing. And when you've started, it seems like a lot of effort not to carry on adding more. If others will have to deal with the code, there's peer pressure to make something maintainable. On this capsule, meh, it's just me.

#ShellScript

back to gemlog


Source