Add quotes around variables and substitution

In Bash, the variables need to be quoted. Fixed strings are fine. See
http://mywiki.wooledge.org/BashPitfalls#A.5B_.24foo_.3D_.22bar.22_.5D to
see more of this.

Every variable could possibly contain spaces, and the output from any
process can contain spaces as well. Therefore it is important to put
quotes around everything.

I also upgraded the tests from `[` to `[[` which is a bash builtin, has
more features and is faster since it does not require a fork. For this
script, it will not matter, but since this is using bash already, one
can use its features. See http://mywiki.wooledge.org/BashFAQ/031 for
more info on `[`, `[[` and `test`.

The backticks are legacy, one can use `$( ... )` in bash that even
allows nesting, see http://mywiki.wooledge.org/CommandSubstitution for
more on this.