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
&&
between your commands. That should tell the second command to wait for the first command to complete. – Terrance Jun 07 '16 at 21:52fg
command would bring it back to the foreground, then you add the;
after then type in your last command. Once you press enter, it will bring your long running command back to the foreground and complete, then run your second command should run automatically. Hope that helps! – Terrance Jun 07 '16 at 22:19