 Hello and welcome. Today we are going to be looking at counting variables in a given string in our bash cell. We're not going to do it perfectly because as we all know in the English language there is A, I, O, U and sometimes Y. So the method we're using, and also I think sometimes W, I think, anyway, we're going to be counting matches to these letters that we're giving. So we can choose to count Y, we can choose not to count Y. There's probably better ways to do this, but we're just doing this to exercise our shell skills and maybe learn a few options for common commands that we may not be familiar with. So let's go ahead and dive right in. We're going to use echo and I'm going to say here I am and that will echo that out. Now we can pipe that into grep and normally use grep to grep through files to find matches and output those lines or at least say this file contains that. What we're going to do though is we're going to use the dash O option which is going to just print the matches on each one on its own line. And what we're going to look for, we're going to put in brackets here and we're going to say A, E, I, O and U and you can decide whether you want to put Y in there or not. Again, it's not going to be smart enough to know when Y is A vowel and not, but again, I'm just doing this for fun. So we're going to do that and what it's going to do is it's going to go through and it's going to print out each one of the vowels that it matches. So we have E, E and A and I put each one on line, but missed I. Why? Well, because we're not doing case and sensitive here. So what we can do here, you can either put capital A, E, I, O and U in here and that should work. Yep, it does, but we don't need to type all that. We can just say dash I for case and sensitive and now we'll get the same output with less letters typed. Great, now we can pipe that into WC, which I always assume stands for word count, which will give you the count of characters and it will give you the count of lines and also the count of words in a file. But if we just do dash L, it will give us the number of lines and since we're outputting each one of our vowels on its own line, we can count those lines and we get four. So there are four vowels in this phrase, in this string. Great, let's go ahead and real quick, just create a script doing basically this that we can give it any string. So we'll just call it, I'll call it vol.sh, you can call it whatever you want. And of course we're going to start off with our shebang line. And I'm just thinking about the name of my script anyway. What we're going to do here is we are going to say, okay, we're going to create a variable called string and we don't have to do this, but it's usually a good idea. We're going to take all of the arguments given and put that into the variable string. And then we're going to create a variable called vowel equals and then we're going to put in here dollar sign braces. And so basically we're going to run a command and whatever the output of that command is will be put into variable vowel and actually let's call it vowel since it should be more than one in most cases. We're going to echo our string variable. Don't forget our dollar sign there. We're going to put that into our grep-o-i. In fact, I think we can just do that like that. It makes it even shorter, a-e-i-o-u. It doesn't matter the order, but whatever. So there we go and now we should be able to echo dollar sign vowels. And if we exit out and make this executable now, I can now run that script. It gives me no output because I have to give it a sentence. I'll say this is my words and it'll give us the vowels there. Again, ignoring that y, which should be counted, but again that's up to us whether we put that in our script or not. So now that we've done that, we can now say count and get our count. Again, we will put this in quotations, braces, or quotations, the dollar sign, and the parentheses. And we'll echo that again into W, C, L. And now we have a count of the variables, or sorry, vowels, into our count variable. So far we haven't given any output that the user is going to see. So let's start with that. We're going to say echo. And we're going to say dollar sign string, STR, our variable there, has dollar sign count vowels. And then we'll say echo. And here we're going to do the dash E option, which I'll explain in a second. They are backslash N. In fact, I'm going to put a colon there just to make it look nice. Dollar sign vowels. So what does that dash E do? Well, dash E lets us use special characters such as this, this backslash N. So basically I'm writing this all on one line here, but it's going to put the vowels on the next line down. If I've typed everything properly, you should be able to run our script. And again, we'll say here I am again. And says, obviously there's typo here. Oh, no, here I am again is my string. Here I am again has seven vowels and then it lists what they are. A, E, capital I, A, A, I. And that's great having them like that. But let's put them all the variables or sorry, all the vowels on one line there. So let's go ahead and go back into our script. And we've created our vowel variable here and then we use it here. And now let's override it here. We can create a whole new variable if we wanted, but I'm just going to override it. And what I'm going to say here is I'm going to say echo, dollar sign, vowels. And I'll pipe that into TR, which will translate. It will take a given character in place with another character. So we're going to say find all new line characters in that list of variables, vowels. I keep saying, well, I guess they are variables, but vowels is what I meant. And we're going to replace those new line characters with commas. So now if we run that same command, it gives us the same output, but instead of each vowel being on its own line, it gives us a list of them on one line there, which is good if there's a lot of them. You know, your message might go off the top of the screen if you're piping it a bunch. One more thing we should do is, you know, give some sort of user output, you know, help output. If you leave it blank, so I don't give any output there. What's saying has one vowel, you know, are we counting properly? One, two, three, four, five, six, seven. Okay, so if you leave it blank, it's telling you there's one vowel even though there are none. So that's wrong. And we want our user to know how to use our program. So let's go back into our script here. And I am going to use a template that I have created. If you're wondering what that chime was, I accidentally hit the modifier key and S on my keyboard, which sends the contents of my clipboard to my phone. I didn't mean to do that, but I'm just going to do this and I'm going to find my check args. This is a little template I have created for Vim. And here we're going to say, okay, check the number of arguments. If it's less than one, then give this message usage. And then we're going to say, I guess I'll do like this, your sentence here. And then I'll also like to give an example, dollar sign zero. Again, dollar sign zero is just whatever the name of your script, the file is, it will put it there and we'll say this is an example. Okay, so now if we were to run our script without any input, it's going to give us that output. And I like, again, having the example here, I can just copy and paste that, do that, and it goes, oh, now I know how this program works. And we can see that there are six vowels, I, I, A, capital E, A, E. And we have I, I, A, capital E, A, E. And so we have counted vowels. Again, not perfectly because we are ignoring y's all together and we can put y's in there, but then it will count y's when they're not vowels. But it was a fun little thing we just did and we practiced some skills and maybe learned some things like the dash O option for grep is something that I never really used before trying this project out. So I do thank you for watching. Please visit filmsbychrist.com. That's Chris of the K. There's a link in the description of the video. There you can search through all my videos. You can also go to the support section and find a link to a PayPal account where you can support me that way or my Patreon page, which is patreon.com, forward slash metalx1000. If you cannot support me in that manner, that is absolutely fine. You can support me though by liking, sharing, subscribing and commenting. I do thank you again for watching. And as always, I hope that you have a great day. How many vowels was in that sentence? How many vowels did I say in this? Oh, we should take this video, transcribe it to text and count how many vowels there are. That would be fun. Anyway, have a great day.