 Hello, today we're gonna be creating a simple little application that is a checklist. So think that you're at work and you have to check items off on a list to make sure that you're actually checking stuff. This is basically a friend, a coworker asked me how hard is it to write an application that is a checklist that checks things are complete? And when people ask questions like that, it's very difficult to answer because you can write something simple like that in a couple of minutes, but programming is like artwork. They say that art is never complete, just abandoned software is the same thing, you can always make improvements. Right in this video, we're gonna create a simple, simple little script, which could definitely be improved upon, but hopefully it only takes a couple of minutes. I'm gonna wing this, I haven't actually, lots of times when I do tutorials, I run through it first, but this should be very basic, so hopefully I don't hit any stumbling blocks. In the next video, we will do something a bit more graphical interface-y, but this is just to show that you can create a fairly good application very quick, but of course you can always make improvements. So I have a file called items.list. It's just a plain text file with just a few items on here that you check the tire pressure on four different tires, you check headlights, strobe lights, and backup lights on the vehicle. So let's go ahead and start writing our program. I'll just call this checklist. So Vim is my text editor. You can use whatever text you like. I use Vim because I like it, and I've got a lot of templates I've created for it so I can easily write out code without having to type everything out as you'll see in the next video. We'll just call this checklist.sh, and here the first thing we're gonna do is we're gonna type in our shebang line. This is just a line that tells the computer what type of program this is. It's going to use the bash interpreter. So now, first thing we're probably gonna want is the user, so your name. And my opinion is in most cases, if you're in a business environment, you probably have logins or should have logins for each of your users, and so you should never have to enter your name. It should know who you are based on who you're logged in as. So what we can do here is we can just say, the name variable equal to, and here we can say dollar sign user. I'll put that in quotations just to be safe. And actually we should actually have a welcome message. So I'm just gonna say echo welcome to the checklist, randomly capitalizing stuff for no reason. There we go. And I can say echo welcome dollar sign name. And one time, and one time only, you have to make that executable unless you move it to another system, then you might have to make it executable again. Then I can just say dot slash name in the file, and it's gonna say welcome, and then welcome to the checklist, welcome MetalX 1000, because that is my username on this system. Now obviously, in a real life scenario, you should have a database of all your employees. And so it should be able to grab your real name from that database based on your username as who you're logged in as. But just to add a little bit to this tutorial, I have created a name.list with a list of random names, and it has three different columns here. It has an employee number in the first column, first name, and a last name. So let's go ahead and, well, actually before we even do that, I'm getting ahead of myself. Let's go back into our program here. Let's say, again, that we're not going based on your username. What we're going to want is to ask the user for the name. So let us say echo please enter your name. And I'm gonna put no new line character there, so we do this all online. And instead of setting it equal to your user, we are going to say, read name. And then I deleted this line, but I'll go back and just say, welcome our sign name. Now I should be able to run that same program. It should say, welcome to the checklist. Please enter your name. I'll enter Chris. He'll enter and says, welcome Chris. Great. You want to, in my opinion, assume the end user is an idiot. And not let them type anything in when you can avoid it. So again, if you can pull their username based on their login credentials, great. If not, then anytime they want to enter something, if you know what they might be entering, it should be something you pull from a list or a database. Because let's try to sort this. And today I write my name is Chris, and then tomorrow I write as Christopher. You know, you want things to be consistent. So again, I have a file here. It's just a plain text file with a list of names. So what I'm going to do here is I'm going to choose name from that. Now again, I can loop through this and have you select from a list. I can display them all. I can have you type in your employee number and pull it. But I'm going to use an application called Fuzzy Finder. It's FZF. If you have this FZF file or program on your computer, it is an amazing program that allows you to filter stuff out quickly. So I can, you know, cat to display those list of names. But if I pipe it like this into FZS, it's going to give me that list of names and not only can I scroll through them, but I can quickly type in a name. And anytime, my opinion, that you have more than say 20 items in a list, you should be able to type to filter to search for you that because no one should have to scroll through a big long list trying to find what they're looking for. So you do that and it returns whatever you selected. So let's go back into our checklist program here. Instead of asking them for their name in that aspect, what we can do here is we can say, please enter your name. And instead of reading the name this way, I can say name and I can say the name equals the output of our command, which is going to be cat our name.list into FZS. And in this case, I am going to run that. It's going to, well, the way it has set up. We miss our message here of entering their name, but this is going to be a quick program. Again, you can clean it up a lot in the future, but let's say my name is Logan Butler. I can type in B-U-T like that. I can type in Logan like that and I can then choose. And right there, it's then replies, please enter your name. We didn't have a new line character there for, because we've changed how we entered that. But we're going to say welcome employee number five, Logan Butler. And of course we can break that up a bit more if we wanted to. I can come in here. First of all, we can do that. And then what we can do is I can cut dash D and I can say delimiter of that and I can say field two comma three. Now, if I run this and I type that properly, I should again be able to take Logan instead of saying, well, sorry. That should be inside this parentheses here. Boom, Logan, choose it. And this time it avoids the employee number. It says Logan comma Butler, which is a little weird because the comma's there so you would think that the first name is the last name. Again, my point here is you can do things quick, but you can keep on improving upon it. But right now we've got their name Logan Butler. If I wanted to just again clean that up, I can say replace the comma with just an empty space here. So now if I say Logan, now it's saying welcome Logan Butler. So again, just showing the point of this tutorial. Again, that you can continuously make small improvements. You can write a program. I could have been done with the entire application if I had just created it, but we're going through different options making it better. Now we need to create a checklist of what we want to go through. And again, we have our items in our file called items.list. So if I do that, now I run this, it's just going to ask us our name. Again, I'll just choose that same name and there's no file that because it's item.list. I don't know why I called it that. I should have called it items. Run it, I'm Logan. And then it lists all the items. What we're gonna do is we're gonna throw this into a loop while read item do done. And then we're gonna say echo dollar sign item. So that will display the item on the screen. And then we want to have the user input. Is it good? Is it bad? Or is it not applicable? So maybe you're checking something, and that thing is not on that particular truck. You can put NA for that. So what we're gonna do here is it's gonna list the item and then we're gonna read and we're gonna say I for item, I guess. It's just a variable, it can be whatever you want. And then we're gonna say, okay, if dollar sign I equals N, we're going to then do something. Actually, for what I'm gonna do like this. L if and else and then end R if then statement. So if it's N, what are we gonna do? So we're gonna be creating a log file. So we're gonna put everything in the log here. So what I'm gonna do here is I am going to also want to get the date stamp that we were talking about earlier. And we're gonna do that for each one of these loops. So right up here I'm gonna say D equals and we'll just say give us the output of date. But then we'll do T for timestamp and we'll give it the output of date that plus percent S, which we'll give us those seconds we talked about earlier. So now we have our timestamp, our date stamp, our item. We're gonna ask the user whose name we already have, whether it's good or not. So here I should be able to put in this, dollar sign I equals N A, then okay, we're gonna create our log file and we should put that in a variable up at the top. So we're just gonna say log equals item.log. Actually, it's like make it a CSV file. You'll see why I meant CSV is a comma separated file. So it's gonna have different columns that are separated by commas. And in fact, just to make things easier here, I'm gonna go back to here and I'm going to get the full name with the employee number there. So here I'm gonna say, okay, if the user puts N, well then we're going to echo our dollar sign timestamp, comma dollar sign date, comma dollar sign, we'll say name who checked it, which we'll actually be putting in their employee number, first name and last name, comma, then we're going to give that output that the user gave, whether it was good or not. But we also need to put the item in there, which is item, so we should probably put that first. We'll say item dollar sign I. And we're gonna put that append it, so two ampersands there into log and that should be dollar sign log. Okay, now we're gonna do the same thing for here. But instead of, well really, I don't have to do an if then statement unless I want to expand again. So really, let's just, for example, I'm just gonna delete that, delete that, delete that, delete that, delete that and go like this. And we should be good, I actually think. So we should check list, I am. Again, I'll just say I'll say that I'm Elijah Flores. And we looped through, it didn't do, it didn't ask me stuff here. So it should ask me, while read item, do this, read. Why is it not giving me the option to, again, I usually run through these things before I do videos. We are catting the list. We are looping through, while read item, do. And we're echoing the item and then we're asking it to read. So I don't know, let's change this to output. Shouldn't make a difference. Somebody watching the video is now going, oh Chris, you're doing this wrong. So give me a second, I'm gonna pause here just so you're not watching me forever trying to figure this out. Okay, so apparently I have never done this before. When you're using the read command in a while loop, you're going to want to add this little greater than or less than symbol to your div TTY. I guess it's to prevent the item that you're echoing here to being piped into there. I can't say I've ever ever doing that before. So I must have never done it before, which is interesting. I must normally do it a different way that I can't think of right now. Anyway, so again, let's just quickly run over this. We're echoing out our list and reading each item. Then we're gonna, I mean the date, timestamp. We're echoing the item and then waiting for the user input. And in this particular case, we're just going dump that timestamp, date stamp, the user's employee number and name, the item they're checking, and whatever they entered into it. So again, this is very simple. I can go check our checklist application. It's gonna ask me who I am. I'll just choose again, Logan Butler. It's gonna ask me, you know, is the tire pressure on the front driver side good? And I can say yes. Is it rear good? Yes. If it's not good, I can say no. And then for headlights, I can say I may, maybe we don't have headlights. I can say yes, I can say yes. And that's all been put into our item.csv, which is, I don't know why I called it that item.csv right there. And it put each item with the stamp and whether it was good or not or whatever the input is. So again, going back to what I was saying before, and I started getting ahead of myself, is here we're putting whatever the user inputs into that item, which might be good because they can type comments and stuff if you want. But going back to what we were just kind of doing before, we can say if, and here I can say dollar sign, I equals N, we can have it do something else, LF, which will also have this. And we're gonna change that to we'll say NA and down here, we'll say YYP. I'm just gonna copy this. Let's talk about what I just did. Here we're gonna say right now, the input's going in as the input, what we're gonna do here is we're gonna say, we're gonna change I in this case to equal problem, whatever we want it to say when they put an N. And here, if they say NA, we can say I now equals, say AN, NA, NA, NA. Not, I don't even know how to say it's all optical. So I'm just gonna, I'm gonna change that to be that just so it's a little bit clearer. And if it's anything else, it can input what they put or we can just say I equals good. Okay, so let's go ahead and run our script again. And if I wrote everything right, it's gonna ask us who we are. This time I'll say that I'm Mason Diaz and the front driver side, I can put anything if it's good or I can just hit enter. I can enter, enter, enter, enter. Oh, the headlights, there's a problem. I'm gonna say N, strobe lights, I'm gonna say NA, backup lights are good. Now, if I cat out our item.csv, you can see that that last column now is, it's good, it's good, it's good, it's good. Oh, there's a problem with that. This is not applicable and that's good. Now, since we did a CSV file with the commas, we can easily look at this as a spreadsheet maybe you don't wanna look at it like this in just a text like that. Maybe you wanna be able to see it a little bit clearer. You can easily use whatever program, Excel, or LibreOffice, I can say item.csv. And when it opens up, it's gonna make sure that we're formatting this properly, which our default should be good. We're gonna say okay. And there we go, we have everything in this. So obviously we could also add in asking for the truck or station that they're at or whatever. I can now sort things. I can sort things and say, oh, show me all things that have problems and I can check the date, has it been fixed, blah, blah, blah. Again, we're just dumping this into just a log file. In real life, you're probably gonna wanna put this into a database, but we're not getting that advanced in this tutorial. Because again, the point of this tutorial is how quickly you can create an application. Now, we've been going for about 18 minutes here, not counting the little issue I had. But in reality, if I wasn't sitting here and explaining this, it would take me five minutes to write this. So yeah, I can write a checklist program that gets all the information we need, timestamps, dates, username, employee numbers, you know, the items they're checking, whether they're good or not. I could have done all that in five minutes. Boom, been done. Now, obviously I can keep on working on this script and making it better and making improvements. For example, here we're going through every item in the checklist one at a time in the set order. It'd be nice if I can go in a different order maybe. I wanna check something else out first, but I can't because I have to go in the order that I'm outputting this list. I could change that. I could use probably FuzzyFinder, the ZF program, so that you're filtering through the list and you can search through the list, check an item and then we'll remove it from your list and you can continue searching like that or you can go through an order. You know, that would take another, not even five minutes for me to add to this program. But again, an application, when you ask someone, how hard is it to write an application? Most basic, especially for business and office applications, you could write something in a couple of minutes and have it functioning, but obviously you wanna add to it. And again, doing a text-based application like this is great. It's super fast. It'll run on, you can give me a computer 30 years old and it'll still run on it. You can use something like SSH to log into the server. That way you have the user's credentials, you're doing everything encrypted, you know it's very secure. There's a lot of advantages to it, but I also get, and even if you were to do this on a phone, I could SSH in and again, I'll have to just keep hitting the enter button when things are good and then when there's a problem just hit enter, it's not that much, it's not super pretty, but I could do this on my phone with no modifications. But I get, it's 2018, people like flashy buttons and checklists and that's what we're gonna do in the next tutorial. Hopefully it doesn't take much longer. This took 20 minutes, should be able to write a pretty nice application. Of course, using interfaces that I've used before, so I have a lot of templates to speed things up and as a programmer, you're hopefully accumulate those sort of things, little scripts to improve your time because a lot of programming is repetitive. So that's what we'll look at in the next video is making a nice little interface that looks nice on a desktop mobile device and allows you to not even have to touch the keyboards you don't want, just checking boxes and picking things from lists. So I hope you look forward to that. I hope that this made sense. Again, this wasn't like a step-by-step tutorial, it kind of was, but I went kind of fast, but the point was on how you can continuously improve your program, even if you write a program in a couple of minutes, you could spend years improving upon it. I mean, look at things like Google. I mean, you go to their webpage, it's their logo and a search bar and that's what it was 20 years ago, but they're still working on it. They've made improvements to it, obviously, especially the backend, but it's a very basic interface that continuously is worked upon. So all applications are like that, it just gets to a point where you're like, I'm happy with this, I'm not gonna improve it anymore until you decide to add something new to it. Anyway, thanks for watching. Please visit my website, filmsbychrist.com, that's Chris with K, there's a link in the description. As always, I hope that you have a great day.