Hello and welcome to command line basics. This video we're gonna learn about Windows Batch scripting. I'm Christopher Hyler and let's begin.
So we're letting objects for this video. We're gonna understand the purpose of a batch. Group four Windows. We're gonna learn how to write a bad script, and we are going to execute a batch fruit as well.
Now, Prius husband. When is the well known file extension for When those bad scripts is it a dot bat
be done batch si dot VBS were d dot Make room.
The answer is a dump that this is the Windows file extension four batch scripts, and it helps Windows file system identify which program it should use to automatically open and execute this file. But that batch is not a valid extension. The dot VBS and dot macro
are different types of scripting files for all Windows and not for bad scripts.
So the purpose of batch groups is very similar to ah, the Lenox Shell scripts. Where if we write a whole bunch of commands that we don't wanna have to keep reading out over and over again, we can type them into a bad script and then we can either double click the file that haven't execute force or executed directly in the terminal,
and we can have other processes executed as well.
So say, with e service control. If we have a specific service where we want it, Thio execute a specific convenient. If it fails, we can use the bat script that we wrote, giving its specific directions and commands to execute and say, Hey, if you fail, we're in this bad script
so it can't be executed by other terminals or other processes. And like we learned, they have the doc bad extension.
So we write a vast script. We have a few different uses. We can have had these labels, which are very useful in order to help loop in a different way than the other Windows loops that we learned.
So if we have this colon for a label, it creates a specific section in the script for us.
And then if later on in the script, if we say, hey, I want you to go to this label, it will go back to that specific spot so as we see, excuse me,
So as we see we put the colon and start here. So this created the label for starting
now it will echo hello as the next command from the command. After that, it says, Hey, you need to go to start and that will send it right back up to the start. And then we'll keep executing down.
It'll say All right, I need to echo. Hello says All right, I need to go to start, and we'll just keep looping in this way. So it's a very useful way to be a little loop inside of a batch file,
so I'll give you a quick demonstration of that. I'm sort of my text files folder. That's I D I R. To see what is inside.
And let's say I have the loop not back knowing Thio do type.
I looked up that to see what's inside, and this is the same file we were looking in that in the Power Point presentation is going to start echo hello and then go back to start now. What's a little different in Windows is that we don't need to do the dot forward slash We can just type the name of the Bash file and hit Enter
and it is going nuts. So I'm going to do control, see
and say Yes, I'm gonna terminate this bad Stroh because I don't want to keep looping forever and ever.
So we can also get very creative with the batch files in the clinic Shel files. And if you haven't learned over the color command it'll use it will change the foreground and the text color of the command window. So if we say hey, I want you to keep changing the color of the background and keep changing the color of the text
go back up to the start. So this is very similar to our last one. Little keep changing the colors.
Now I'm going to run this command. And if you don't like a lot of bright flashing colors, then I suggest you go ahead and skip forward about 30 seconds. So let's have the color's Not that I'm gonna execute this, and it is going absolutely not. So I'm gonna terminate that and say we're done.
But it's a very useful way to kind of loop through and get creative with what we're doing with the batch files,
so execute bad scripts. As we've already learned, we can take the file. Name two reclaims the command prompt so we can do Just color is not bad like we just did.
Now you need to be in the same directory as the file you're going to execute. If you are not in the same directory, then you would either need to type the full folder structure that absolute path for that file.
So that is a another way to stay inside the same working directory year in but also access that file in a different directory.
It's a post assessment. How do you create labels in a basket? Is it a semicolon B colon? See parentheses or D. Ford slash
answer is B a corn. This creates the label that we can use the go to command in order to keep looping or create different functionality. Insider pat script. So it's very useful to keep this in mind while you're writing these vast groups in order to be able to become effective at what you're doing.
So in this video we learned we understood the purpose off a bad script. We learned how to write a bad script, and we executed a bad script from the command line, and I hope to see you in the next city