 Well, this video is part of a series. We're going over the basics of shell scripts in these first couple of weeks of this series, and we're going to be going over everything to go over in this video today in more detail on future videos. But whenever you learn a new programming language, there are four basic things you need to learn how to do. They should be the first things you learn how to do, and it's going to be the majority of your programming. Those things are display a message on the screen, get user input, save it to a variable, be able to read and write to files. So we're going to go over those few things and a couple of other things real quick today. And then I'll go over the more detail in future videos. So first thing is writing a message to the screen. So we use the echo command is one option and I'll hit enter now. You don't necessarily need in all cases to have the quotation marks, but it's a good habit to get into. So echo and then whatever you want to display back and again doing this right here in the shell seems kind of silly, like why would you do that? But putting that into a script, it makes more sense, which we will do in a moment. Next will be the read command. The read command will get user input. So I can say read X and that will, I can hit enter here. It's going to wait for the user to type something. And so I'll just type in Bob. And when I hit enter, it has now put the string Bob into the variable X. So now I can say echo and in shell scripts, dollar sign indicates a variable. So here we're saying not to echo this literally, but to echo out this variable of X, which now equals Bob. Now you can use read in cooperation with echo or you should be able to use dash P to display a message first. So I can say pick a number, I'll hit enter, it says pick a number, I can press eight and then when I press enter, the variable X now equals eight. So I can echo out that variable. So we've learned how to display stuff to the screen, woops, displayed stuff to the screen, read user input and even how to read user input with a prompting message. Next we want to be able to read from a file. I can cat on or we have a file here called names.txt. Then you can see all I have to do is say cat and that's short from cat to Nate. And basically you can display one or more files using this command. And this is the contents of this text file. If I want to add a name to that file, I would say echo John. Now if I did one greater than symbol and then the name of the file names, it will overwrite that file and replace the entire contents with just the word John. But I want to append to the bottom of it. So I'm going to use two of the greater than symbols and that means put John into this file or wherever the output of this command, it doesn't just have to be the echo command. The output of whatever command this is, take the standard output because there's also an error output. We'll go over that in future videos as well. But take the standard output and append it. So two greater than symbols means append to the end of this file. So I hit enter there and now I can say catnames.txt and you can see it has now added John to the end of that list. Another command is clear and there's other ways to do that but as far as scripting you can use the word clear. Now I'm going to use a text editor to have a look at a script that I've written. I'm using Vim but you can use whatever text editor you like. Nano, Emacs, Kate, G-Edit, Mousepad, whatever as long as it's a text editor and not like a word document editor or office document editor. So here we go. This is a script I just created which basically incorporates everything we just went over. Now the first line of any script on a Unix or Unix like system such as Linux should be your shebang line regardless of whether it's a shell script, a Perl script or a Python script. It should be and some people leave this out. It should be your shebang line. This is telling your computer, your operating system what interpreter to use and as we mentioned there's different shells. This is telling us to use the bash shell which is the default on most systems. So even if you default shell something else this is saying when you run the script use the bash shell if available because there are some differences which I'll point out one here in a moment. First thing I like to do with a lot of my scripts is clear the screen so we have a nice little clear. Then we're going to echo out the message hello and then we're going to display the message please enter your name and we're going to put whatever the user enters into the variable name. Then we're going to put that name. We're going to append it to the end of our names.txt file. We'll clear the screen again then we'll echo out hello and the user's name and then the backslash n when I use the dash e on echo here indicates a new line. So this will be on the next line. I could just use two echo commands but I'm just incorporating into one here. It says your name has been added to the list. Next we're going to display the list by catting out that file name. Then I will say goodbye to whatever the person's name is. And then the sleep command sleeps for two seconds right here is what that's doing and it's like to add that just for a little bit of a here's the information. Now the program's done running. Once that's saved you need to make your programs executable. So we'll say change mod x and we'll say the name of your script. So now that script is executable. Now to run the script since it's in our current folder we're going to do dot slash and the name of our script. I'll go over that more in the future videos but dot slash just means this is in our current directory rather than somewhere else on the computer. Without that it's going to try to look for it in a system path which we'll also talk about in future videos but right now it's in our current folder the directory we're in and if I hit enter it now runs that script it says hello please enter your name my name is Chris. I'll hit enter it says hello Chris your name has been added to the list it gives me the list my name is at the end it said goodbye Chris and then it waited two seconds before exiting the program. Now as I mentioned we did the shebang line at the top. Now if you leave that out it's going to try to use whatever your default shell is which may or may not be bash and my default shells I've mentioned in the previous video is Z shell so now I'm currently in Z shell and I'll show you one difference another difference that I may have not mentioned is that the read command with the dash P gives me an error. So the read command works different in Z shell so although I use Z shell as my default shell in my system most the scripts I write I write using bash because that's the most common used shell out there for desktop systems on Linux and Mac OS I'm not sure what the default shell on something like one of the BSD operating systems is or some other operating systems but bash is most common when it comes to Linux and it's the default shell on Mac OS. So yeah so make sure you have that shebang line it's rather annoying when people don't have that usually people are pretty good with shell scripts but then they go to Python scripts and forget to put that in there it's just rather annoying. Anyway that is the basics again we looked at printing to the screen reading user input displaying files and writing to files that is going to be the majority of what you do in any program you write a lot of what else from that is just like when you read from a file or you read from user input is just filtering that data cutting it up and sorting through it and formatting it certain ways but a majority of you do I just taught you what you're going to do in most your scripts so I thank you for watching be sure to watch the rest of this series there should be an annotation in the playlist or an annotation in the description of this video for the full playlist I thank you for watching if you enjoyed this video be sure to like subscribe share and comment and if you really like my videos and want to become a supporter you can go to patreon.com forward slash metal x1000 there should be a link to that in the description as well where you can support me financially and even like a dollar a month is helpful I get a lot of people doing that so thanks for watching and as always I hope that you have a great day