# The /bin/sh Blog. Part I: Timmy's Templates I love Unix shell scripting, in fact I may enjoy it more than "actual" programming. I say "[shell scripts](https://wikipedia.org/wiki/Shell_script)", as opposed to "bash scripts", simply because I don't use bash for my scripts. The reason why is not relevant to this post. What *is* relevant is *why* make a blog using shell scripts? Well, *why not*? After all, Makefile blogs are a [thing](https://lobste.rs/s/0skwhg/idea_makefile_blog) that [exist](https://github.com/MaskRay/makefile-blog), and Makefiles are just one way of running commands to do *something*. Hmm. I wonder, what's another way of running a bunch of commands? > Oh! I know! Well, what is it Timmy? > Why, shell scripts of course! Woah, thanks Timmy, why that's correct. > But how will you ever manage a website's HTML layout all in a shell script? > Wouldn't that get messy? Why yes Timmy, it would get pretty messy. What we need is some kind of "template" which can take some input and output HTML which we can serve... > What about that old M4 thing? "M4", Timmy? What on earth is that? > RFTM dude: https://en.wikipedia.org/wiki/M4_(computer_language), https://man.openbsd.org/m4 Okay Timmy, no need to be rude now. We have guests, remember? Ignoring Timmy's rude nature, we now have a way of making "templates" of sorts, to make building the HTML a little easier. First, we'll start with something (almost) every HTML document on the web has, a ``: ``` define(`_HTMLHEAD', ` My Blog Lol ') ``` Okay so now we have a `_HTMLHEAD` macro defined. In our m4 file, whenever we type `_HTMLHEAD`, the `` containing our blog's title and a link to our stylesheet will be printed. There's only one problem, currently on every page our title is exactly the same. That is fine for some things, but for actual posts we should be able to set our `` to be the title of our post. With M4 this is a piece of cake: ```m4 define(`_HTMLHEAD', `<head> <title>$1 - My Blog Lol ') ``` > Well, what changed? See Timmy, on the second line, there is now a `$1 -` before the rest of the blog title. In M4, macros can have arguments that can be placed into the macro's content. Now, if we call ``_HTMLHEAD(`This is a post')``, the resulting HTML will be: ```HTML This is a post - My Blog Lol ``` The `$1` has been replaced by our first argument, as expected. Nice. We can define more macros; for the navigation, footer, whatever you like. Here's a simple one that includes a `` and also a `