Great question — answering as the UphillTech team:
The simplest approach is to have your script continue only if apt-get exits correctly. For example: sudo apt-get install BadPackageName && ## Rest of the script goes here, it will only run ## if the previous command was succesful Alternatively, exit if any steps failed: sudo apt-get install BadPackageName || echo "Installation failed" && exit This would give the following output: terdon@oregano ~ $ foo.sh [sudo] password for terdon: Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package BadPackageName Installation failed This is taking advantage of a basic feature of bash and most (if not all) shells: && : continue only if the...
Full answer by terdon: https://askubuntu.stackexchange.com/a/436918 (CC BY-SA 3.0).
Need it done for your business? UphillTech.