 Okay, continuing with our week of shell basics, working in the, in this case, Linux terminal, but this will work on a lot of other systems, not Windows, I mean, unless you have something like Sigwin installed, but basically what we've gone over this week, we'll work on like a Mac OS, BSD, as I mentioned, Linux, and a lot of systems, really pretty much anything but Windows should have some sort of shell in it. I mean, Windows does have its own thing, but it's different than everybody else because they just got to be that way. So, and I figure today we can actually write a script. You can use any text editor that you'd like make sure it's a text editor and not a word processor, like you don't have to be using LibreOffice or OpenOffice or Microsoft Word or something to write this out. You want to use something like gEdit or Kate, I believe is KDE's, but since we're working in the shell, you might as well edit in the shell. Normally I use Vim, V-I-M as my text editor of choice, but it might be a little advanced for some people. We're going to use Nano today, which is also a little more common on like stripped down systems. It tends to be there quite often, and if not, it should be available in many cases, but use whatever text editor you feel comfortable with. I'm just going to use, once again, it's called Nano, and then I'm going to give it the name I want to call it. I'll just call it My Script, and this isn't necessary, but .sh indicates that it is a shell script. That's just for the user. It doesn't affect how it works at all. Unlike a Windows system where the extension, what's after that last dot there, tells the system what type of file it is in Unix systems, that's pretty much for most parts for user knowledge, so I can quickly look at it and go, oh, that's a shell script, not necessary at all. I'll tell you what is necessary, is once we go in here, is the first line of the script is called the Shabang line, and it's pound exclamation mark, exclamation point, forward slash bin bash. It doesn't have to be bash unless you're using bash, which is going to be very common. You might see ones with other terminals on a very lightweight system. It might be SH, which is just a standard shell. Bash is born again, shell, it's another shell, and there's many out there. Basically what this is saying, because as far as the system is concerned, this is a text file. It's no different than a letter you write. It's no different than another scripting language like Python. This first line tells the system this is a shell script. Now, if you leave that out and you run it in bash, or through bash, it knows. But let's say you're running in another shell like the SH shell, or Z shell, or TC shell, or TC, yeah. Anyway, there's a lot of, a lot of shells out there. If you don't put this there, and you try to run it, and your code isn't compatible with that shell, it's not going to work. But most systems have bash installed. It goes, okay, this is a bash script, use the bash interpreter, the bash environment. So very important, not extremely necessary in all cases, but important to put because it will cause headaches later down the road if you don't. So pound, exclamation mark, forward slash bin, forward slash bash, just saying to use bash interpreter. At this point, we just write out a list of commands. So let's go over the stuff we learned this week. Let's first off, I like to start off most of my scripts, if not all, by clearing the screen, makes your code look clean. Then we'll ask a question. I will say echo dash n. At this point, someone's going to ask me, oh, nano doesn't color code on my machine. I'm not going to get into that today. Some systems, depending on how you set up, it's in the config file, whether it color codes or not, you may not get colors like this in nano on your system unless it's set up to, in which case just Google color coding nano. So echo and color coding makes it a lot better for noticing mistakes in your code. So echo dash n, and I'll say what is your name going back to our first tutorial here. Actually, I'm not going to, I'm going to put the name on your line there. Unless I put it, it all depends on how you want it to look. I'm going to put the no new line. I'm going to say enter your name and then put a colon there with a space. That looks like, like it's wanting you to put it at the end of the line there. So clear the screen, print echo, enter your name. And then we're going to say read. Remember, this waits for a user input. And we'll create a variable called name. And that variable be whatever the user inputs. Then we will clear the screen again. And then we will echo out. Hello, name. And don't forget your dollar sign. That way it knows to use the variable and not just the word name. Hello name, echo. And what should we do next? We will say, oh, here we go. What is your favorite color? What is your favorite color? Question mark. And I like to capitalize random words. Don't ask me why. So what is your favorite color? And then here I'll say read. Now create a variable called color. And now I will echo out. Echo dollar sign color. And this is case sensitive. Don't put a capital C there if you did not put a capital C when you created the variable. So echo color is a good color. I also know there's different ways to spell color. That's how I spell it. And there's not a right way in a wrong way. There's just different ways to spell color before someone comments on that. I don't know if it's every live part of the world part of country, whatever, but echo color is a good color. So it's not going to say color is a good color. It's going to say whatever color the user inputted. Inputted input. Inputted. Yeah. So and then we will say echo. Now saving that info. And then we can say echo dollar sign name, name, favorite color is. And then we'll say dollar sign color. But we're not going to print that out to the screen. We're going to put that into a file called color dot log. And then we will clear the screen again. Well, I don't want to clear the screen at this point, because it will go so fast you won't see any of that stuff. So I will say actually I'll clear the screen up here. I just like to clear the screen because it keeps things looking fresh. So now we'll say echo data saved echo. Please always be nice. Say please press enter to continue. And then we'll just give it the read command without a variable. And it will just wait for the user to hit enter. And then we will clear the screen. And then we will say that's the end of our script. Well, maybe we should have some sort of exit message. Echo have a good day dollar sign name. And then we're going to hit control X to exit. Y to yes save. And it says you want to write to this file my script that sh enter. Now we have that all in that script. Now, there's two ways can run this. We can say bash. And then the name of the script. It's not the best way to do it, in my opinion. What you should do is change mod to make it executable. So change mod plus X, the name of your script. What that is doing is saying to the system, this is a script. And I as the user am giving this script permission to run. Because otherwise, it would not work. You try to run it and it just would not execute. It would give you an error message of some sort. But now that it's executable, we can run it by giving it since it's in the folder we're in, we're going to say dot forward slash dot slash my script. And when we hit enter, it starts. It says enter your name. My name is Chris. Enter. It says hello, Chris. What is your favorite color? I'll say blue. I actually really like black, but black is not really a color. So we'll say blue. We'll hit enter. It says blue is a good color. Now saving that info. Data saved, because it was just a little bit of data. It only took a fraction of a second. Please press enter to continue. We could also have wrote exit because that's the end of our script. It says have a good day, Chris. So and if we go back to a little review here, LS, you can see all the files in this folder. And there is one called color log. And if we cat that out, it says Chris, favorite color is blue. So let's go back into nano. I'm hitting up arrow to go through my history. And let's quickly review our shebang line. Very important saying this is a script and what type of script it is. It is a bash script. We're going to say clear the screen, echo. And don't put a new line at the end of this and then wait for the user input and then save that input as the variable name. Clear the screen. I did that last time too. Clear the screen and then echo. Hello, whatever the person inputted. Echo. What is your favorite color? Save the user input as the variable color. Clear the screen. Use the variable color is a good color. Now saving that info and then it's taking the variable of the name and the variable of the color, putting it in a sentence and appending it to this color log file. So if we run the script again, it will actually add it as a new line to the file. And I'll show you that here in a second. Then we have a few more messages. We're using the read command without a variable just to wait for the user to press enter. Clearing the screen, having an exit message. So real quick, control X to X add that if you're using nano. Once again, it's already executable. We made it executable with change mod so we don't have to do that again. But I'm going to say dot slash tab to auto complete here. And I'm going to hit enter to run it again. What's your name? I'll just say James. And this is hello James. What's your favorite color? And I'll say James's favorite color is red. I'll hit enter. It says red is a good color. Now saving that info at that point saves it data save. Please press enter to continue. And it says have a good day James. So now I can cat out our color log file. And since we appended by using the greater than greater than rather than just one gate greater than it will add it to our last line. So both lines should be in there now cat color dot log. We've got Chris favorite color is blue. James favorite color is red. Really probably should have a comma there or something or apostrophe s but you get the idea. So I hope you enjoyed this week of review on basics in the shell basics in the terminal. Once again I have plenty of tutorials if you want more go to my website. If you want me to do more on the basics of the terminal shell because I've been getting into a lot of more advanced stuff recently. If you want me to do a lot on basics I can go back and do more videos on basic stuff like this. The way you let me know. Go ahead and comment but also give this video a thumbs up. You know that's the way voting you know all the videos in this series. If I get a lot of thumbs up people liking it I know that I should do more videos on the basics. If not I'll just continue doing more advanced stuff and you can watch the old lower quality basics that I've done. But I'd probably would like to do more tutorials on unwrap and cut and said and Ock which is more intermediate stuff I guess. But my old videos on that stuff is rather low quality but they're doable. So it's like should I redo them? Do you guys not care? Are the old ones good enough? Let me know by liking this video. Also if you enjoy this video if you're new to this be sure to check out my website filmsbychris.com that's Chris of the K. There's a link in the description of this video. And I have plenty of videos there. I've been doing this for a couple years now. I hope you enjoyed it. Please subscribe. I put out videos regularly. Check out this whole playlist of shell basics. There should be an annotation or something in the video description linking you to the entire playlist. And I just thank you for watching. I hope that you have a great day.