I'm not immediately seeing what your question is. Does the existing code work? If not, what does not work correctly?
Eventually, it looks like you need the if / else construct. Here is an example, copied from the Advanced Bash Scripting Guide**:
Code:
if [ $t −lt 5 ]
then
return 0 # true
else
return 1 # false
fi
In place of the test ([...]), substitute your test, and in place of the return statements, you would substitute the desired commands.
**Available at
http://tldp.org, but I would start with Bash Guide for Beginners (same site)