I love bash's -x option for exactly this type of debugging. It prints out every command before running it, so you can see what is different about the command as the script is running it
bash -x my-script.sh
Off the top of my head, I'm guessing the inline shell command $( ... ) is eating your double quotes, and I bet you should escape them, particularly around username and password