 So we've been looking at progress bars in our shell scripts, and I'm going to go over the final example today Which is using zennedy to get you a gooey interface But I quickly want to review our last progress bar which used dialogue in the shell Because zennedy basically works the same way except for when I was just testing it out It actually works more efficient you would think the the dialogue box in the shell would be work better More efficiently than a gooey interface, but turns out as any I guess with the shell interface It's got to rewrite all the characters to the screen over and over again where the gooey it just updates the current gooey Would be an assumption on why it's a more Efficient but let's look at examples that last time I used for the but let's just use sequence. We're gonna just Sequence out number one to a hundred boom only takes a fraction of a second Let's do that same thing, but we're gonna pass it to dialogue So we're just counting from one to a hundred, but we're saying dialogue display a title display a gauge and go ahead and So you can see between this which takes a tenth of a second to this which takes about two seconds That's a big difference now We can do the same thing With zennedy so actually let me just say here is zennedy and I'm going to say Sequence one to a hundred boom it's done already it actually calculated all out and went to it But let's slow that down a little bit. Let's put that back into a for loop So here we're going to loop from zero I instead of using sequence I'm just using brace expansions, but we're counting from one to a hundred and again if I was to just do this even with the loop Into zennedy it just it just happens instantly But if I was to come in here and add in a sleep command Tell it after each number sleep for a tenth of a second. We can see we have a nice looking progress bar So that's the basic concept of creating a dialogue with or a progress bar with zennedy when it's done We can click okay, but I've made a more elaborate script Just to show you because people might see I go okay So that's counting from one to a hundred, but how do I actually do something and calculate out the process well again? If you go to my get lab page get lab comfort slash middle X 1000 and search for my project that shell Progress bars you'll get this script and the other ones from the previous video but This is the example I have so what we're gonna do here is we're gonna set a directory Here I'm just gonna say my root directory So what we're gonna do is last time we were just looking at my temp director We're gonna log all files for my entire computer is gonna take a little bit longer because there's a lot more files But then we also need this gonna work just like our last example with dialogue We need to get a count what count are we currently at but then we also to get a percentage We need to know what what the total is so here we're gonna say okay We're gonna run the fact the fine command on whatever our directory is here It's our root directory dump any errors to Dev know because I may not have permission to look at certain files and folders But then we're using W C L to count how many files are so we're gonna get a total number of files Then we're gonna echo out the total number of files just so the user has some information Why would I even do that because we're working with a GUI interface, but whatever? Then here I'm going to then again do the same thing again again having a progress bar Where you're cacking out a percentage slows down your process a little bit because you need to calculate out your total to begin with Depending on your circumstance it may be a few seconds, but it could also be longer depending on what you're calculating out But here we're gonna loop through each file Each time we count if we find a file we're going to add once the counts We're gonna go zero one two three four and then we're going to take that file name and dump it into our log file Okay, so that's what we're doing. We're just logging it, but you could be moving files or Some other process But we we're doing whatever this is where we're doing whatever here and then This entity again the only output from this loop can be a number for our percentage. Okay, so Here we're saying take the Current count so if we're on the third file Take take that number and multiply it by a hundred and then divide it out by our total That's just how you find the percentage of something in math. That's not a computer thing That's just how math works And so we're echoing that out to our zennedy and zennedy. I'm just saying progress bar now Our example I showed us a zennedy progress. I've had some things to hear here We're adding a title so our dialogue box has a title It says scanning files and then the text over the progress bar says logging files and then we have percent here You leave that blanket automatically starts at zero But you can have it start at 50% or 10% Depending on maybe you calculate out part or something before then you close dialect It's something else and you're coming back and you're getting a total percentage Whatever we're gonna start at zero You don't need that there if I delete that out that would the script will run the same But I put it in there in case for some reason you want to start at a different number But again if I now run our zennedy example Scanning files again this part takes a little bit. I got a total number of files And now again, it's looping through every time it finds a new file It adds one to the count it logs that file to a log and then it does some math That takes what current number on multiplies it by a hundred divides that by our total which is Let's see one million one hundred and sixty two 590 files that's files on my machine files and directories on my machine that my current user is allowed to View and it's going through and you see it's taking a while because that's a lot of files Now if I was again as I mentioned in previous videos was to just dump also files It would all those files to the log file. It would go much quicker But because we're looping through stuff and calculating out stuff for the progress bar. It's slowing things down but With your script you may be doing more than just logging stuff to a file and so this example is just again Basically, if you're prior processing something out, you would do it right where this line is you'd add all your your stuff there Just make sure that it's not piping anything out because if I was to let's see what happens if I go echo I'm not even sure what's going to happen now So I'm going to echo out the file and so it's going to give echo out the file name and then give the count And I don't know if that's just going to crash sanity if we're going to get Errors or if it's zen is just going to ignore the other ones. Let's see. Let's see what happens Oh It actually is still it must be ignoring the ones that are Just lying that aren't numbers. So that's good to know I don't think dialogue does that So actually let's do this. Let's let's go up to Dialogue here, but I want in the for loop There we go. Uh, let me let me see what happens here if I after each number Echo out test Oh, I thought that that would mess things up. It must be ignoring all information other than Um Other than the numbers that it's looking for Although I assume if I'm echoing out a number that might mess something up. So let's let's run that again And let me just say here 50. Yeah, so that 50 is making it do that So, uh, that's good to know. I'm learning things as you're learning things. Let's do the same thing with our zenity command Let's go for a loop zenity. What happens if I say Echo 50 Yeah, it's doing the same thing where it's counting up stuff, but then it keeps on flipping back to 50 So that's that's good to know that it will ignore any, um string text Uh, but numbers will uh affect the progress bar. So that's good if your script is Outputting information. It's not messing up our dialogue boxes. I just learned something new along with you See we learned together as always. Please visit films by chris.com and I hope that you have a great day