 Hello and welcome to this video. We're going to be looking at dialogue and progress bars with our shell scripts today. I've already done two videos, the first one where I demonstrated all the different types of progress bars that I'm showing in these tutorials, the last one we went over PV, which is in the shell. Today we're going to be doing, using dialogue, which will allow us to have a progress bar right in our shell, but a little more graphically pleasing to the eyes than PV. We're going to be using the program called dialogue, which there's a good chance that's installed on your Linux machine already because it's commonly used by a lot of programs. But let's go ahead and dive right in and just look at our progress bar here. This is what it looks like. Basically what we're doing here is we're counting up all the files in our temp directory. I did that because there was a good number of files in there without being too long but also not too short. And then we're looping through and calculating out the percentage. Now again, to do this, we need to know the total number of files first so that we can calculate out a percentage because dialogue wants to know, in this particular case, the way we're doing it, what percentage we're at. So let's go ahead and look at this example. So again, we're going to count, we have to count each time we log a file. So we want to start at zero. That's what this variable count is here. And then total, we're going to use the find command to list out all the files in our temp directory, dumping any errors into dev null. And then we're using wc-l to count each line, so each file that we come across. Then we're going to echo out a message for the user. And then we're going to use the find command again to log these to a file, to a text file. Again, this part up here doesn't take very long in this example, but it could on some projects and you may not want to do this because it may slow down what you're doing. You're slowing down your progress to calculate your progress. But once we have a total count, we can use some math to figure that out. So each time we log a new file, we're going to add one to count. Okay? So we're saying count, start at zero, then it's going to one, two, three, four for each file. Then it's going to log that file name to a log file. And then here, we're going to echo out the percentage we're at. So we're just doing basic math. So how do you get the percentage of something? Well, you take your current count right here, we're multiplying that by 100. And then we're dividing that by our total count in the end. So, you know, if it's 200, if you have 200 files, and we're currently at 100, 100 times 100 divided by 200 should give us 50%. And then we're going to just dump that percentage. Dialog just wants to know the percentage. So in this loop, nothing can output anything to the screen to be piped, other than the percentage, otherwise it will screw things up. So here we're going to say dialogue, then we're going to give a title for our dialogue box. So I'm just going to show up the top, it says logging all files. And then our gauge, our gauge is going to have a message here. And then these numbers are here just sizing for how you want things on the screen size. So don't worry about those too much. Just leave them, but just leave them as this. And let's go ahead and run that again. And there we go. So again, as I talked about in previous examples, we're using a loop here to actually log all these files and dump them into a file should only take a couple of seconds. But because we're running through a loop, it's slowing down our progress. Depending on what you're doing, if you're just doing that, you probably need a progress bar because again, it would just take a second or two to actually do this. But because we're using a loop and we're dumping each line one at a time, it's slowing things way down and then we're doing math to calculate it out. Again, a good example of this is not the most efficient way to do this, but we purposely did this so that we can have dialogue that's visual. Otherwise, it's not, there's no point of having a dialogue if it takes a progress bar, if it only takes a few seconds. So again, this is our progress bar command right here. Dialogue, we're giving it a title, we're giving it a gauge with a message and then some sizing. All dialogue is looking for is a current percentage. So let me actually, I didn't plan on doing this. So let's see if this works. I'm going to say for I in, and then we're going to say, oh, here we go, auto-completing something I did in the past. Here I'm going to just echo out dollar sign I. So we do that and we don't need a quotation mark here. Here we go. So it gave us 1 to 100. I could pipe that into our dialogue here with one pipe command and it will go through the progress bar, but you can see just having the progress bar slowed that down. So without the progress bar, with the progress bar. But that's basically what we're doing is we're counting from 1 or even 0 to 100 and passing that dialogue. And that's how dialogue generates the progress bar. So that's an even simpler example right there. But I wanted to actually show doing something that's why in the actual script we're going through files. Because someone will look at this and may not know, well, how do I actually utilize that with dialogue? So I create the script with the loop where it's actually calculating up files and dumping them into a log file so that you can see how that's done. But this is the basic concept there. Maybe I'll add this to the notes on the project on GitLab. But I hope that makes sense. And I hope that you have a great day. This is filmsbychrist.com. That's Chris with the K. There's a link in the description. As always, I hope that you have a great day.