Conway's Game of Life in Bash, but it's a bit cursed

The other day, I learnt about how, when bash does arithmetic expansion, it evaluates variables as a whole arithmetic expression, instead of just an int; which leads to crazy fast[1] recursive “functions” being completely doable.

As a normal adult with a life, I have totally been reasonable with my new found hammer that is so, so, so, so beautiful, and pretty, and useful, and there’s just… so many nails around to hit I can’t believe my luck-

A-hem, anyway: k8s3dnih9's solution for Conway's Game of Life in Bash on Exercism

I tried my best to keep things labeled understandably, at the very least. Beyond the recursion stuffs, it’s a fairly basic bit mask approach, I added a whole paragraph at the end explaining it.

Overall, I do think it’s a feature of bash(and ksh too, apparently) that has been seemingly around since forever ago but had gone rather underappreciated. (not for a lack of reasons tho: set -x is useless here, and I sure had a blast debugging all that, but still!)


  1. since the slower bash interpreter only has to evaluate the command once ↩︎

3 Likes

… with great power comes great responsibility…

2 Likes

ksh is pretty wild. Too bad it was proprietary for so long. You can do some really interesting things with it

I didn’t know that! That’s actually kinda crazy that you can do floating points and kinda-OOP with ksh, I might get shell envy lmao.