 Okay, we're continuing where we left off in the last video. So if you didn't watch the previous video, be sure to go and check that out. Otherwise, you might be a little lost in this video. Other than that, we're working with the Bash shell. We've already started writing our first script. Let's continue it and see what we can do. Okay, where we left off last time, we have this script that we're writing where it says, welcome, and then it's gonna ask for the username and it's gonna print out hello and that person's name. So let's go ahead and exit add this. And again, I'm using Vim as my text editor. Use whatever text editor you are comfortable with, but Vim is a great program if you take the time to learn how to use it. I'm gonna say dot slash. Again, the dot slash just means run. This is in our current directory. Look at this file and it's gonna say, welcome, enter your name and I'll say Bob. Okay, I'm gonna hit, I can type in clear to clear the screen or hit control L. Let's go into our script and just let's add that in. Let's go ahead and just type in clear at the beginning here. Now, if we were to save that, run our script again. Again, I started typing for slash my and hit tab to autocomplete and it says welcome, enter your name and it cleared the screen. Got rid of the text that was on there and I'll say Tim and it says hello, Tim. So another command that I didn't show yet is the sleep command. So I'm gonna say sleep one and what that's gonna do is gonna sleep for one second. Now, if we run our script, it's gonna say, clear the screen, say welcome, wait one second and then prompt the user to input their name and I'll say Timmy and it says hello, Timmy. Okay, you can also do things by default, sleep uses seconds, you can say m for minutes, h for hours and you can also do like dot five if you wanna go a half a second or dot one for a tenth of a second. So we're asking them to enter their name and then we're gonna echo that out and then what we can do is we can say sleep for another second maybe. We're gonna say read dash p for prompt and we can say enter a friend's name. I'll say friend and then down here, I can say echo dollar sign name is friends with dollar sign friend. So now if we run our script, it's gonna clear the screen, wait a second, ask for your name and then it'll say hello, Tom and then it says enter your friend's name, I'll say Tim and it'll say Tom is friends with Tim. So that's great. Now in the previous video, I showed you that you can do something like echo and use dash e and say something like this is a line, backslash n, this is line two and it puts a new line where this backslash n is because we have this dash e option. Without the dash e option, I hit insert instead of home. It doesn't recognize that backslash n if you don't have that dash e but when you're in an actual script here and another thing you can do is do something like this. I can just put things on multiple lines. So I can say echo, this is a line, this is another line, this is the last line. Oops. And now when I run my script, I'm gonna say Tom and Tim and then it prints all those just as you would just as it looks in the file. So be aware of that that you can do multiple lines when you're using the echo command. Now continuing from something we learned last time was we learned about putting information into a file. So let me go ahead and delete this and I'll just echo dollar sign friend added to friend list. And what I'll actually do is here, I'll say echo dollar sign friend and I will put that into a file called friend.lst. Which again, the LST means nothing. It's just a file extension. It's still just a text file. The greater than greater than means appends that file. We'll create it if it doesn't exist and then append to it. So we're creating a friend list here. So we can now run our script and I'll say that I'm Tom and my friend is Tim. I typed a little too early and that kind of mess things up, Tim. So now if I list out my files again with the LS command, you can see that we have this friend list file. I can use the cat command to see what's in there. If I run my script again, I can say that I'm Jack and my friend is John. And if I was to cat out our friend list file, you can see it has Tim and John in there. So now I can go back into my script and I can say sleep. I'm just using the sleep commands here just to give the user a chance to read this message before continuing. And now we can say echo, here is a list of your friends. And I can even use your name. And then down here I can say cat and I'll say friend list. And now I can say run my script. I am Tom and I will say my friend is Jack. And I'll say Tom is friends with Jack. Jack added to friend list. Here is a list of, gotta fix that, your friends Tom and it will list out my friends. Let's go ahead and fix that little typo. Where was that, was that right here? If I was to run the script again, I'm Tom and my friend is Sally. And it lists out my friends. Now if I was to run the script again and I was typing Sally, oh, I put that as my name, my friend is Sally, that's fine. You can see that Sally's now in that list twice because we're just appending to that list. Well, there's another command, it's called the sort command. So if we were to go back into our file here, we should be able to use the sort command directly like this. And what this is going to do, we'll run our script and I'm gonna say my name is Tom, my friend is Chris, which is fun because that's actually me. And here it didn't just list out the file as is because I was to cat out that file. You can see that it goes the order that we entered them into. Well, we just sorted them using the sort command alphabetically. Now you see that Sally is still in there twice. If we were to go back into our script, we can say dash you. And what that's gonna do is unique. It's going to sort them alphabetically but then remove any duplicates. So if we were to run our script again and I was to even enter Chris again. So now technically Chris is in the twi... Oh, that is who I am. My friend, if I was to enter as my friend, Chris, now Sally's in the list twice and Chris is in the list twice but when it prints it out with our program it's gonna say Jack, John, Chris, Sally, Tim. But if we were to cat out our friend list, you can see that the names are still in there multiple times and they're not in order. So our program's just outputting that. Now, another option with the sort command that is used commonly is maybe dash R. And what that should do is sort it, unique it, but it's sorting it reversed. So it's gonna do it in reverse alphabetical order. So again, I'm Tom and I will say that my friend is John. And I'm purposely typing John with lowercase j here because you'll see that, oh, John was already in there with lowercase j. Anyway, it did it backwards. Let me run it again. I'm gonna say I'm Tom and my friend is John with a capital J. John with a capital J and John with a lowercase j as far as the sort command is concerned is the same or different names because capital J and lowercase j are different letters. I'm gonna go ahead and clear the screen. Now, let me real quick, I'm just gonna say sort. Again, dash unique and our friends file. Again, John's in there twice. If I was to say dash ash ignore dash case, it's going to drop that second John there because it's going to realize, it's going case insensitive. If we do, I believe the same command, shorthand is F and you should be able to do that like so. I just realized that seems a little inappropriate. Let's fix that, we'll do this. There we go. So, lots of times you'll have longer commands, options with commands and then a shorter version. And we'll look into the man file later on which shows you all your options. We'll look at that when we get to the date command because we're gonna do a lot with a date command. It's a very useful command probably in the next video. So let's go back into our script. So my script, we're gonna come down here and I am going to say FRU. So we're saying that we are going to sort it. We are going to unique it. We're going to ignore the case for the duplicates and then we're going to reverse the list so it's in reverse alphabetical order. We'll run our script, my script, welcome. I am Tom and my friend is Bob and Bob has been added to the list and John is only showing up there once. So another great program is the TR command. And what the TR command does is it's used to replace certain characters. So for example, let me show you actually, before we get to the TR command, let's talk about piping. So you can take the output of one command and put it into the input of another command. This is one of the strongest features of a shell. So for example, if I was to run this, I can say echo, Chris, I can pipe that. Well, oops, that will echo it out. If I say pipe it, so the pipe character is on at least a standard QWERTY keyboard is shift and the pipe is just above the enter key, but you have to hit shift in that. It's just a straight line up and down that says take whatever this program is outputting, which in this case is Chris and put it into the next program so the next program can do something with it. So in this case, I can show you TR, I can say TR, the capital K, and I can say lowercase K and it will put a lowercase K or I can make it an R. So it's RIS, okay? Another example of that is a lot of people will use the cat command and pipe the output of that into different things. So I can say friendless, I can then pipe that into sort, so that's not as efficient as just saying friendless, you know, because now you're running two commands, you're running this command and then this command, but you can take the output of any command and pipe it into another command. And again, one of the commands that is very useful that is on pretty much all systems is the TR command and it allows you to replace certain characters or even delete certain characters. So I can say echo, right, again, I'll say Chris and I can pipe that into TR and I can say dash D, K and that will just delete any K. There could be multiple Ks in here. I can say Chris of the K at the end and they're deleted both those Ks and it is case sensitive. So if I was to put in a lowercase K, it's going to ignore that lowercase K and just remove the uppercase Ks. We'll do more with the TR command in the future, but again, it's very useful, especially for example, if I was to cat out our friends list here, right? I can say TR and as we learned previously, backslash N means new line, well here I'm saying dash D which means delete any new line character. So now it just moved everything onto one new line. If I want to, I can run that command again, but instead of saying delete, I can say TR, all new line characters and make them a space. So now instead of everything being on its own line, it's moving all in one line, it replaced those new line characters with spaces. So if you ever need everything put on one line, that's one way to do it. Anyway, I'm going to stop here on this tutorial. We moved a little bit forward. In the next video, we're going to look at the date command, which is probably a lot more powerful than a lot of people realize. So I hope you look forward in that. Filmsbychrist.com, that's Chris the K. There's a link in the description. Be sure to check out my page, visit it. You can search through all my videos there. Up in the top corner, there's a support section. You click on that and there's lots of ways you can support me. Patreon, PayPal, Libre Pay, Buy Me a Coffee, but also if you can't afford to support me financially, think about liking, sharing, subscribing, commenting. And as always, I do thank you for watching and I hope that you have a great day.