From 15f47f7bd74cd0ade0c95a1234f243438b46ad15 Mon Sep 17 00:00:00 2001 From: davidovski Date: Tue, 25 Jul 2023 14:23:18 +0200 Subject: added article on shebangs --- site/entries/shebangs.html | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 site/entries/shebangs.html (limited to 'site/entries/shebangs.html') diff --git a/site/entries/shebangs.html b/site/entries/shebangs.html new file mode 100755 index 0000000..31ab9a8 --- /dev/null +++ b/site/entries/shebangs.html @@ -0,0 +1,24 @@ +#!/usr/bin/md2html + +# shebangs + +When working with a unix-like system, you've no doubt come across shebangs, like the little `#!/bin/sh` at the top of your shell scripts. The way these work is actually really simple: if you have a text file with a shebang and you set the execute bit on it, you can execute it as if you've invoked the interpreter in the shebang with that file. + +For example, if you have a shell script, `script.sh`, and you place a `#!/bin/sh` at the top, executing this file will essentially run the `/bin/sh` program with the arguments `script.sh`. This probably seems quite straightforward, but it does mean you can do some pretty cool stuff. + +## shblg + +Using this simple feature, I decided to re-write the static-generator for my site. Instead of running a single python script that will convert markdown files into html, shblg takes source files and "executes" them. I wrote a small program that takes a markdown file as an argument and converts it to html and writes it to stdout, naming it `md2html`. With this, I can place a shebang at the top of each markdown file, `#!/usr/bin/md2html` and then execute the markdown file to output an html file. + +All shblg does is it recursively executes each file in a given site directory, writing their output to files in the output directory. While this does have some limitations, it can be very easily extended to any sorts of file, and since files are executed with any generic interpreter, they can contain any sort of logic like listing files, or calculating dates. + +## source + +if you want to check out the code of shblg, you can clone it with: + +`git clone https://git.davidovski.xyz/shblg.git` + +and if you want to check out how i used it for the code of this site, you can clone it with: + +`git clone https://git.davidovski.xyz/davidovski.git` + -- cgit v1.2.1