Time
5 hours 21 minutes
Difficulty
Beginner
CEU/CPE
6

Video Transcription

00:00
Hello and welcome to command line Basics. This very where Delenn links shell scripting and how we can use it to our advantage at the command line. I'm Christopher Heller. And this begin.
00:10
So we're learning objectives for this video. We're gonna understand the purpose of a shell script. Learn how to write a shells group, and we're going to execute a shells group
00:20
Pre assessment. What is the well known file extension for eight Lennox Shell script, is it a dot shell be dot s h c dot script or D dot Shh. Script.
00:34
The answer is B dot s h. This is the well known file extension for a Lennox Shell script that dot s h the dot shell that script Dutch shell script. I mean, you can make them all you want, because limits on its own kind of ignores file extensions.
00:52
But as far as for the community and four systems, this is a well known extension to help keep track of these files.
01:00
So the purpose of shells groups is that they're used to automate processes.
01:04
This is figure similar to the four in the wild loops that we learned in the previous video, where it will execute, you know, specific processes for us without us having to do them over and over. And as we learned in the pretty assessment, they usually have the dot S H extension for a shell script extension.
01:22
And it's really useful that help provide all of this different functionality that we've already written in for commands to run.
01:29
That way, we don't have to type them out individually or keep typing them over and over again. So it's a very useful way to keep track of these commands and to be able to execute them quickly.
01:40
So when we have right a shell script, we need to start with, they should bang at the start. That is that hashtag exclamation point.
01:49
Now what this does for a shell script is that tells Thea Lennox system, which specific shell interpreter it needs to use in order to run this command.
02:00
So if we use the shebang with flesh, been slash bash, that is just using the bash L for linens. And if you're not very familiar with the different types of shells from Lenox at recommend looking world, so you can become exposed to these different shells and find one that works best for you. But as far as Ah, staying at the shell bash is very good.
02:19
And it tells you know this interpreter.
02:22
Hey, I need you to use this specific interpret. And so if we were running a Python script with uses, shebang and say, Hey, you need Thio access the Python libraries and they will automatically interpret the script with Python instead of with the bash.
02:38
And if you're not familiar with programming already, we use just a single hashtag that's used for comments to help comment out different parts of code and will not be executed.
02:49
So writing a shell script, we're gonna use very similar functions as the one line four and wild look that we learned previously where we have her shebang at the top
03:00
and then we have the same, you know, four eye where we're defining that parameter in this list of numbers, I want you to echo I.
03:08
It's important. Thio. Keep in mind that we have this different type of tabbing for the shell, and it's a lot easier to read into trouble. Shoot if we need to do that and we have the done as well
03:21
so Let's go ahead and give an example of this script.
03:24
So if I'm gonna do l s
03:28
dash L. A
03:30
and I have my echo loop, it does show.
03:32
So let's go Nano
03:35
echo looped a shell to see what it looks like And I have my shebang here have our four loop and the done
03:43
So let's exit and we're gonna run it just like any other program were used that don't forward slash
03:49
Let me spell it correctly Echo loop that s H and run and it goes ahead Spits out exactly what we told it to one through 10 Echoed So this is a very useful way to be able to write and execute the shell script.
04:06
And so, as as we learn, we need to do the dot ford slash and then the name of the file in order to execute it. And just like any other executed will file, we may need to change the file permissions with the Jamaat command that we learned from three previous video
04:24
and the make sure you have that execute permission set so we may need to do to Moloch plus X and then the name of the file in order to execute it.
04:32
So it is very useful. And you need to keep this in mind when you're writing your shell scripts and if you don't have permission to run them, that's most likely because don't have that Execute permission set.
04:45
All right. Supposed assessment. You're right. A shell script. But you don't have the permissions to run it. What command do you execute?
04:50
Is it a nano?
04:53
Be them. See, I have config wor d jamaat.
04:59
The answer is the kebab. We're changing the filed mode bits in order to have that execute permission to run our code.
05:06
The Nano command is very useful to write the code similar with the vim where we can write our shells gripped but they're not used to execute the program or configure their permissions that executed and the I have config Command is used for networking for interface that working and it's not used to help
05:26
execute any scripts.
05:30
All right, so in this video we understood the purpose of Shells Group who learned how to write a shell script. And we also learned how to execute a shell script that we wrote And I hope to see you in the next video

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