The issue was two fold. I had mistakenly used -z in the bash logic rather than -n which is the opposite logic that I intended. I always get this wrong as I remember "-n" as meaning "not" which is not the case!
From man bash section CONDITIONAL EXPRESSIONS
Run this command if you wish to see it
man --pager='less -p ^CONDITIONAL\ EXPRESSIONS' bash
-z string
True if the length of string is zero.
string
-n string
True if the length of string is non-zero.
This fixes #2
Explanation from the issue: