 We've been working on exit codes and last tutorial we looked over how to see if a directory exists or not and today in that video I had a viewer ask if there's a easy way or a good way to check to see if a program is installed within a script. Obviously if you use aptitude here I'll give you an example. We'll use aptitude search and we'll use Apache as an example. There's a bunch of Apache packages but you'll see some of them will have this I next to them. That's one way you can quickly look okay I means that it's installed. That's one way of looking at but in a script if you want the script to continue differently based on whether a program is installed like if your script depends on a program they can check to see if that package is installed and if it is installed continue and if it's not you know advise the user that needs to be installed or maybe even try to install it itself. So the way we're going to do that once again is with exit codes but we're going to use a DPKG and DPKG is this is for Debian based distros so Debian, Ubuntu, Linux meant a lot of distributions if you're using something that's not Debian based this probably won't work for you but DPKG Debian package system basically it's what's used to install Debian packages aptitude apt get synaptic all these programs I'm pretty sure using DPKG in the background if you were to download Debian file you could use DPKG to install the Debian file but you can also check things with so I can say dash s and I can say something like nmap and if I hit enter there it gives me the information about nmap the current you know version that's installed we can also do something like Apache now you got to give it the package name so here I'm searching Apache which I do have installed but if I hit enter you can see here that it gets an error it's not installed it's because the package in my case is actually called Apache too so it's important to know the name of the package you're searching for because you're not necessarily searching for the program that's installed you're searching for the package that's installed but if you're writing a script and you're using DPKG using a Debian based distro you should know what the package is installed when you're writing the script so if I do DPKG dash s I assume stands for show it will show the information about Apache to package and there you can see that it is status is installed and it's okay so now if we do that now if I say echo dollar dollar sign question mark to get the exit code you can see it exit with a zero in that case but if I do it again without the two or with any package name that's not a package that's installed or a package that doesn't exist you get this now if I say echo dollar sign question mark I can X code of one so now we know that when we run this command that we're going to if it's zero it's installed if it's one it's not but we do get output with both of these so what we're going to do is let's say we'll try with a patchy here we'll say ampersand greater than symbol and we'll redirect this into dev null so we're just taking the all the output whether it's you know standard output or error output and it will be putting it into null so basically just throwing it away so now I can say echo one because you know Apache does is not installed but Apache 2 is installed because we get a zero so we can check that exit code and continue in the way that we need to for our script so if you're not understanding exit codes watch my previous videos there should be a annotation somewhere in this video that will link to the entire playlist for this year's shell script tutorials and the ones previous to this will be the ones you're looking for or you can go to my site or my YouTube channel and search through my videos I'm sure if you just search exit codes the videos on exit code should come up so I hope this helps you out that's just one way of doing it once again this is specific to Debian based distros but you could do something similar I'm sure with Red Hat distros with RPM but it all depends on your package manager but if you're running once again a Debian based distro you should be set with this this should work for you I thank you for watching please is it films by Chris dot com that's Chris the K there's a link in the description you can also go there to search through my videos and I just hope that you have a great day also remember if you have technical questions try not to ask them in the comments here is a good chance they're not going to get answered technical questions or if you just want to hang out and chat feel free to join the RRC channel I have set up on free note it's pound films by Chris it's Chris the K if you go to filmsbychris.com you can also click on the link for the IRC up in the menu also all those links should be in the description of this video once again thank you for watching and have a great day