Well, first of all, you aren't using proper shell syntax. Setting variables is done with "
var=value". There's no "
$" in front of the variable name, and no spaces around the equals sign. The dollar sign is only used when expanding a variable name back into it's value later.
Second, I can't actually understand your request. What exactly is this script supposed to do? What, exactly do the input values look like, and what exactly is the output that you need to get from it?
For general string manipulation techniques in bash, see here:
http://mywiki.wooledge.org/BashFAQ/100
And
QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
Finally, be aware that, since environment variables are generally all upper-case, it's good practice to keep your own user variables in lower-case or mixed-case to help differentiate them.