Sure you can do that, simply add an && or || at the ending of the line depending you want the action be done if the previous command succeeds or fails. So for the following example I use the usual upgrade stuff but it works with almost every command.
#!/bin/bash
# an example upgrade script, call with sudo ./scriptname.sh
apt-get update &&
apt-get -y dist-upgrade &&
apt-get -y autoremove &&
apt-get clean
This would be for a script which only forwards on succession of the commands before. note that the last line has no &&, that is because it would throw you an error if it where there, because there is no next command to jump to.
Now an example for a failure, shall we? Taking again the same example but I want my computer to tell me how silly my action was (kidding):
#!/bin/bash
# an example upgrade script, call with sudo ./scriptname.sh
apt-get update &&
(apt-get -y dist-upgrade &&) || echo "THIS was not working right"
apt-get -y autoremove &&
apt-get clean
So this would in case the command fails output something, for more reading on the bash shell scripting you can visit the links I included here:
http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html
http://mywiki.wooledge.org/BashGuide