tests: Fix warnings reported by shellcheck
This commit includes following fixes for a few shell scripts:
Follow the best practice of quoting variables everywhere unless they are used in places where word-splitting and globbing can never happen.
commandwith $(command) because the latter is easier to use and read.
Don't use "$@" in places expecting a string because it is an array of strings instead of a single string.