Repeating Ourselves Less with M4
7 points by zk
7 points by zk
Solving this is non-trivial. While m4 does have something akin to escaping, it doesn't quite work like it does in other languages and it's brittle enough for me not to even bother with it in this post.
Instead, we'll reach for another trusty Unix tool, sed
I ran into a similar issue when my blog's custom static site generator was written in shell scripts+M4.
I wrote a post about how I wrote the generator and because I had included snippets of M4 in the post, it put itself into an infinite loop at one point.
I too added some sed as a bandaid but I ended up scrapping using M4 because it just became a can of worms in escaping certain stuff...
However, using M4 for simple configs here is a pretty fantastic idea I might steal.
Very fun read! About this bit:
Instead, we'll reach for another trusty Unix tool, sed. If you've ever used s/old pattern/new pattern/ in Vim (or other editors and, for some inexplicable reason, Discord), you already know what sed is capable of. It takes a command and executes it on the lines of a file.
Surprisingly, the /s/pattern/replacement/ in-band editing command crops up in the most surprising places. My favorite instance was Skype, way back in the early 2000-teens.
I cannot give an authoritative answer to this. In my case, I want my VPS to be largely "self-sufficient". That is to say, I'd like to follow the OpenBSD philosophy and rely on tools already present on the machine rather than install extra stuff. This is both a fun challenge and also makes the system very "fire and forget."
I love this approach and try to follow it as well. Just using POSIX tools feels a bit spartan but the resulting longevity of your scripts (let's be frank -- it's mostly sysadmin-type scripts like the ones the article demonstrates) is well worth it.
Also, I understand OpenBSD makes extensive use of Perl, it being part of the base system and all, but I've never actually sat down to learn it. One of my colleagues in a previous job did sit down and learn enough perl to get work done on an extremely locked-down server (no python, ruby, etc.)