 Okay, once again, all this week we're doing shell script basics, so if you're working in a Unix or Unix-like environment, you're probably going to have a shell that you can work with, bash is one of the most common, but not the only one. They're all very similar, and most of what I'm teaching in these basics should work throughout all of them, but I never said that it definitely will, but should for the most part. And we're just getting back to basics because my old videos, the quality, was pretty low, so I want to give a little updated look. And today, well first let's review what we went over last time. We went over new line characters. When we say who are you, I don't know. I can say dash n means no new line at the end of this, so I can run another command, another echo command, echo, who are you, and I can say, I don't know, blah, blah, blah, I don't even know what to type. So I'll hit enter, and even though these are two separate commands, the first one is not going to put a new line at the end, so it should all print out on the same line. There we go. At the same time, if I wanted to, I can put new lines within the command. If I do dash e, it tells it to look for these special backslashed characters, so I can say dash n, backslash n, which means new line. So everywhere I put a backslash n, as long as I have this e here, it will put a new line. I will hit enter, and you can see each thing is on a new line. So that's quick. Oh, and then clearing the screen, you can either type clear and hit enter, or if you are actually working in the terminal, not just writing a script, you can press control L, and it will clear the screen for you. So today we're going to look at saving stuff to a file, and then we will read what we put in the file, and we'll also work on appending the file. So creating a file, adding stuff to it later on, and maybe overwriting the file. So let me real quick here, makedir. I'm just going to create something in my temp directory. Temp directory is something that clears out, should clear out every time you restart your computer, so I don't care about this, so I'm just going to put it in here. Oh, I'm kind of, okay. I wasn't playing on teaching about makedir, but since I'm going to here, makedir, and we'll get into it more in a future tutorial, means makedir. So I'm going to make in a directory, and I'll call this temp tutorial, and kind of ignore what I'm doing right now. I should have done this before I started recording, but we will go over it later this week, and I'll control L to clear the screen. Okay, so right now I am in a folder, and I'm going to say echo hello world, and it puts it out to the screen, right? Well, let's say I want to save it to a file. So I can say, same thing, once again, hitting up arrow brings me to my previous command, and I can do this greater than symbol, and this is telling it to take the output and put it into the file I name, so I'll just call this output.txt. Make it a little bit easier to read up with some spaces there. So now when I hit enter, we don't see it on the screen, hello world, it actually went into a file that we just created. Now, to read from that file, I'm going to use the cat command, which stands for concatenate, which I'm not going to explain, but basically it prints out what's inside a file if we give it a file name, and there's another thing, you can type out the whole name, output.txt, or you can always start typing in most shells, you can press tab and it will auto complete for you if that file exists. So anyway, cat, output.txt, which is what we just created, if I enter, it says hello world. Once again, I'll hit up arrow twice just to go back to the previous command here, and I'll type the same thing, I'll say hello Chris, that's me, and I'll hit enter. Now, if we cat out, once again, I'll hit tab to auto complete that, and now the file says hello Chris, our hello world is gone, because we overwrote the file. Now, let's say we want to add a new line to that file, not overwrite what's in there, but just append to it. Well, once again, we'll say echo and we'll say hello world, and instead of doing greater than, we'll do greater than greater than, and that means to instead of once again overwrite the file, we're going to append to it, we're going to add to it. So we will say once again the same file, I'll type in ot and hit tab to auto complete. Once again, since that file exists, otherwise it wouldn't find it. I'll hit enter, and now if we cat, which once again reads the file, tab for output here, enter, and now that file contains two lines. So, we're writing to a file, created the file, when we wrote to it, we read the file, we appended to it with the greater than greater than, and then we read it again. So now let's append to it again. I just want to show you just to add something from a previous tutorial. I'll just say this is new, but what I'm going to do here is I'm going to say dash e, and I'm just going to put my little new line character there. So now when I hit enter, and I cat out the file that we have, you can see it does recognize our new line character, so new is put on the end there. And at the same time, let's say I say hello world again, but I say dash n, and hit enter, which means no new line at the end of the echo command, and we cat this out. You can see when we cat it out, we say hello world, and there's no new line at the end. So there is no empty line at the end there. So if we were to actually do that a second time, so echo, no new line, hello world, we're appending to our output file, and once again the output file, you can name whatever you want, or within reason. Once again, avoid special characters, and you should avoid spaces, and we will hit enter, and if we cat it out now, you can see the last line says, whoops, did not mean to resize that. Let me cat that out again, because I messed everything up. We'll say, it says hello world, hello world, and then our command prompt, because there's no new line at the end of the file. Now if we were to do it again, hello world, a third time, once I'm gonna control L to clear the screen, because it's getting too long there, so hello world, and this time I removed that no new line, and I cat out our output file. You can see it went on that same line again, because the new character at the beginning, there is no new character at the beginning, and we didn't put a new character at the end, or new line at the end, but the new line character we put the end here allows our command prompt to be at the end here. I hope that makes sense. I kind of sound like it didn't make sense. Basically just realize that if you don't put a new line at the end, the next line you add will be on that same last line as the last thing you added. Okay, so once again reviewing with the clear echo, and this doesn't just work for the echo command. Any command that has standard output, and there's different types of outputs, there's standard output and error output, but most time you're going to be working with standard output. Any program that has any type of output that comes to the screen can be redirected into file. If it's not standard output, you got to do it a different way, but so we're just using the echo. We're going to work with other commands in the future and put the output of these commands into a file, but just remember, you can echo one greater than means create or overwrite a file to mean append to that file. And also, if the file does not exist, it will create it there as well. So let's say I was to say to output greater than greater than that file does not exist yet. It does now cat to tab to autocomplete. There it is. So once again, working with basics this week, putting out a new video every day this week, hopefully. Just going back to the basics. We're going to continue our advanced stuff on video editing command line next week. I hope you enjoyed this tutorial. If you did, and you want to learn more, be sure to one subscribe to my YouTube videos because I put out videos regularly to check out the playlist for this this series of shell basics. Hopefully I'll remember to put an annotation or a link in the description. And like if you go there now, there might be some videos that aren't viewable yet because they're not released yet, but they will be by the end of this week. But that's only going to be an issue if you go to the playlist this week. But so check out those videos. Go to my website filmsbychrist.com. That's Chris the K. There should be a link in the description. I've got hundreds and hundreds and hundreds of videos, not only on shell scripts, but Python scripts and a bunch of other stuff. Everything should be broken down into playlists. And I just hope you subscribe, enjoy and learn. And I hope that you have a great day.