News for hackers. Stuff that matters.
Re:Notes on the M4 Macro Language (2008) by luizfelberti on Friday April 03, 2020 @03:59PM (#22773386)
M4 is so impotent and crippling difficult to use, that it led me to create my own dumb templating engine[0] because there is no standard POSIX tool that will let you, simply and in the dumbest way possible, substitute strings within a file.

If you try using awk or sed, you will need to figure out a magical way to escape whatever arbitrary value you are trying to replace, so you don't break sed's regex or awk's syntax.

M4 was one of the last things I tried, and it was an utter disaster. If any of M4's magical characters collides with the syntax of the file you're trying to template: tough luck. And there is no way to escape your file for M4 either, it's syntax doesn't support that.

I eventually discovered that Bash 4.4+ has some built-in functions for "dumb" string substitution[1], which is exactly what's missing from the default POSIX tools.

Since then I wrote this little wrapper around that functionality, as a simple, single-file, dependency-free Bash script. If you find something like that useful, it's on the link below:

[0] https://github.com/luizberti/templ

[1] https://www.tldp.org/LDP/abs/html/string-manipulation.html

Re:Notes on the M4 Macro Language (2008) by vePhi4le on Friday April 03, 2020 @08:08PM (#22775094)
`envsubst` is not POSIX, but my preferred tool for such things: https://linux.die.net/man/1/envsubst

it's part of `gettext`: https://www.gnu.org/software/gettext/manual/html_node/envsub...

Re:Notes on the M4 Macro Language (2008) by MarkSweep on Friday April 03, 2020 @08:01PM (#22775071)
There is likely already a simple templating program installed on your linux OS: envsubst. It is included as part of the gettext-base package on Ubuntu and installed by default I believe.

https://www.gnu.org/software/gettext/manual/html_node/envsub...

The templating language looks similar to capability to that provided by templ.

Re:Notes on the M4 Macro Language (2008) by diroussel on Friday April 03, 2020 @04:58PM (#22773889)
Would perl or ruby not suit your requirements?
Re:Notes on the M4 Macro Language (2008) by luizfelberti on Friday April 03, 2020 @05:59PM (#22774356)
Ruby most definitely wouldn't, it doesn't come pre-installed on almost any AMI/server/Docker Image/etc.

As for perl, it does come "with the system" more often than Ruby, but also not as much as bash.

Even if it did, I reckon bash is something that nowadays people are more accustomed to than perl, and would consider it more of a no brainer.