Port to POSIX shell

So that it can be used on systems without bash / where bash is not used
for startup because of speed.
Much simpler, not sure why I used an array really!