a$ is probably $a, $ at the end is quite unusual. And probably will not do what you want.
Learning variables, quoting is not trivial in bash, but you can have help to understand it.
At first there is a man page and
other documentation too (just look for bash quoting).
Also you can use
set -xv in your script to check how it is really working and also you can check your script using shellcheck (or similar)