thanks guys, using && finally got everything to work right.

one of the problems i had was the variables were being unset at the end of the script so they didnt even exist at the time the statement was being executed.