diff options
author | davidovski <david@davidovski.xyz> | 2023-07-25 14:23:18 +0200 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2023-07-25 14:24:19 +0200 |
commit | 15f47f7bd74cd0ade0c95a1234f243438b46ad15 (patch) | |
tree | 690f62210ea7ac9d516851bc32eb9b5235d70d6c /site/entries/shebangs.html | |
parent | 263749ff7380f1459d25a4c0d1bfed6b3af45495 (diff) |
added article on shebangs
Diffstat (limited to 'site/entries/shebangs.html')
-rwxr-xr-x | site/entries/shebangs.html | 24 |
1 files changed, 24 insertions, 0 deletions
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` + |