Bash has a -n option that will
Read commands but do not execute them. This may be used to check a script for syntax errors.
It will output to stderr and set $? to 2 if there is a syntax problem. You could use it on .bash_profile like so:
bash -n .bash_profile
if [[ $? -ne 0 ]]
# handle an error
Based on the comment string, I can't help but add a suggestion for adding these global variables in a different way. Consider a somewhat-contrived case where the user's .bash_profile had a "return" at the end of it. Appending anything (like variable assignments) would be skipped by future bash invocations. Consider putting these global variables under /etc somewhere (such as /etc/profile.d, assuming that those files get sourced by your /etc/profile); that way, you can set them based on various shell syntaxes (csh, bash), and you don't have to check to see if they're set in the user's environments OR mess with their environment files.
Another alternative would be to put these global variable assignments into a custom /etc file of your choosing, and adding in code to the .bash_profile files to source that file if it exists. This has the same disadvantage of your current plan -- editing user's local files -- but added flexibility to use different global files for different users / scenarios.