Time
5 hours 21 minutes
Difficulty
Beginner
CEU/CPE
6

Video Transcription

00:00
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.
00:08
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.
00:19
Now, Prius husband. When is the well known file extension for When those bad scripts is it a dot bat
00:25
be done batch si dot VBS were d dot Make room.
00:31
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
00:49
are different types of scripting files for all Windows and not for bad scripts.
00:56
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,
01:15
and we can have other processes executed as well.
01:19
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
01:37
so it can't be executed by other terminals or other processes. And like we learned, they have the doc bad extension.
01:46
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.
02:00
So if we have this colon for a label, it creates a specific section in the script for us.
02:07
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,
02:16
let me get my pen.
02:19
So as we see we put the colon and start here. So this created the label for starting
02:24
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.
02:39
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,
02:50
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.
02:55
And let's say I have the loop not back knowing Thio do type.
03:01
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
03:20
and it is going nuts. So I'm going to do control, see
03:23
and say Yes, I'm gonna terminate this bad Stroh because I don't want to keep looping forever and ever.
03:30
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
03:50
and then
03:50
go back up to the start. So this is very similar to our last one. Little keep changing the colors.
03:55
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.
04:15
But it's a very useful way to kind of loop through and get creative with what we're doing with the batch files,
04:20
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.
04:30
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.
04:43
So that is a another way to stay inside the same working directory year in but also access that file in a different directory.
04:51
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
05:02
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.
05:20
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

Up Next

Command Line Basics

In this course you will learn the fundamentals of Command Line, a fundamental tool for any user of Windows and Linux machines. Command line allows developers to manipulate files easily and quickly. Learning command line saves developers time and resources.

Instructed By

Instructor Profile Image
Christopher Haller
Senior Intelligence Operations Analyst at Centripetal
Instructor