 Today, we're going to be looking at numbering stuff with your shell scripts, whether it be files or just generating a list of some sort. And of course, you could have issues with organizing them by sorting them by order. Let me show you what I mean. So I'm working in bash here, I'm going to say 4i in. And if I do, I can say zero dot dot 100, and I'll say do echo dollar sign I done and it lists out all the numbers. Actually, it's more than overkill for that particular command. But let's look at it a little bit more. Let's say I wanted to name a file, I'll call it image, let's do all our case, image underscore dot jpeg. So let's say we wanted to create a list or these files of jpegs. And you can see it generates them nicely in order. We got zero, one, two, three, four, five, six, seven, eight, nine, ten, all the way through to 100. But what happens if we try to sort that, have the computer sort it and we wanted them to be in order? Like let's say you have all these files and you want to make a video out of them, you got to keep them in order. Well, a lot of programs, if it was trying to put them in order, like piping this into the sort command, you can see that they get a little out of order because it goes image nine is next to 90, eight is next to 80. If we go all the way up to the top here, you can see zero, one, ten and a hundred are next to each other. And then we jump to 11 and go through to two. So that's not really good to have the files labeled like that. What you want is a leading zero, something like this. Let me clear the screen. We're going to say echo. We want the file names to look like this, image 001 dot jpeg. You know, or depending on how many you're going to have, if you're going to have more than a thousand, you might want it to be four digits or five digits. So you would start at zero, zero, zero, zero, one, so forth and so on. So how do you generate that with a script? Well, instead of using the echo command, we're going to use the print command or print F command, I should say print F. And then we're going to say, OK, here we can say image underscore. And instead of typing out the number here, what we're going to do is we're going to say percent sign zero dot two. D dot jpeg or whatever your extension is, that should be a dot. And if I hit enter here, and we're going to want to put a new line character. If we don't put a new line character, you can see it ends up on the same line there. So we're going to put a new line character. And as you can see, we get image 00 dot jpeg. And if we wanted to be three zeros or three digits, I should say, we can change that to a three. And if you're going to go over a thousand, but other 10,000 with your numbering, you might want four. OK, so that gives us our zeros. How do we input our number? Well, we put it after our quotations. So we got print, print this out. And basically we're saying right here, think of this as like a variable saying it's going to be a four digit number. And if you don't tell what number, it's going to put zero. But outside the parentheses, if I say one, we now get zero, zero, zero, one. And again, if you want it only three digits, you can say we want it to be a three digit number. Or if you want it to be a five digit number, five digit number. And it's whatever number you put out here, I can go two, I can go three, I can go eight. If I go 10, you can see it's still only five digits, which is exactly what we want. So let's put that into a loop and check it by sorting it just like we did earlier with the echo command. Control L to clear the screen there. So again, I'm going to say four i in so we're creating a variable. And that variable is going to loop through from zero to we'll say 1000. Well, we'll start off with 100. And we're going to say do print f, which is similar to the echo command, but has some different functionality. We're going to say image and we're going to say percent zero dot two d for a two digit. But really we're going up to 100. So we want it to be three digits. And we'll say dot jpeg. And if we were to give it a new line character and say done now, it's just going to say image zero, zero, zero dot jpeg for all of them. So what we need to do clear the screen again is again outside our quotations here, put our number. But in this case, our number is our variable dollar sign i. I'll hit enter now and you can see we get zero through 100. Great. Same as we did with the echo, but now let's try to sort it by piping it into sort and we get the same output. The numbers are in order as they should be. Now, if we do give it a bigger number than a three digit number, so let's say we went to 1000 or even 2000. We do have an issue there sorting. Let's take the sort command away. So even if you put a bigger number than the digits you tell it, that's great. It will it won't crash or anything like that, but we have some four digit numbers and some three digit numbers. So be sure to set this variable to the maximum number of digits in the number that you're going to input. So if you're going to be doing anything in the thousands, you're going to want to be four digits because 1000 to 9999 is four digits. I set this back to 1000 for now. We'll hit enter and you can see, well, I'll do it again with 2000 and we will sort that and now they are sorted properly. So that's the key right there is to put the correct number of digits that you want. So that's it. That's it. That's numbering files. We're creating a number list with leading zeros. So let's sort that and less it and you can see that we have 0 0 0 0 0 0 0 1. And if we were to keep going down the list, we have our leading zeros, then we hit 1000 right about there. Great. You know, that's exactly what we need. I hope you found this tutorial useful. Again, I think my patrons over at Patreon.com forward slash Melix 1000 for sponsoring this video and choosing bash videos for this month's topic and the shell script tutorials. I hope you find them useful. If you do, please visit filmsbychrist.com. Think about supporting me over at Patreon.com forward slash Melix 1000 and as always, I hope that you have a great day. I would like to take a moment to thank the following patrons who made this video possible by supporting me over at Patreon.com forward slash Melix 1000. Bash. No, I know you're not. I'm not bashing you. Obviously, I use bash more than I probably use see. Right. So, you know. But my point though is, is that you are, what are you saying? Right. If you enjoy my tutorials and would like to see more, please think about contributing to my Patreon account at patreon.com forward slash Melix 1000.