Linux - Basic shell scripting
48K views
Nov 28, 2024
Linux - Basic shell scripting
View Video Transcript
0:00
So into our earlier video we have discussed about the different type of shell and we have also seen about the bash shell
0:07
Now I'm going to write some basic particular commands or basic programming into my batch shell
0:12
But before we start we should know how we can create a bas shell scripts
0:17
So for that we need to follow some rules that will be better for you if you follow those rules and create your script files or create your programs
0:25
So let's see what the rules are. Very first, whenever you are writing a script
0:29
you are writing a particular script that should be added in the order like what the
0:34
scripts are very first scripts are certain list of command which we are going to add
0:38
into a particular file so what will happen if you are adding multiple commands
0:43
it will run those commands step by step automatically just when you run the file
0:47
so those kind of file we can add but while you are adding the file while you are
0:52
adding the different commands into a file you should know you are adding it into a
0:56
proper manner means you are adding the first command which you require to be run first, then the second, then the third
1:02
So all these particular commands or instructions should be given in a proper order
1:06
That with the first thing we need to follow. The second thing what you need to follow is whenever you are writing a program
1:14
always ensure that you are providing a comment to all the particular lines or all the particular instructions
1:21
Because if you are writing a huge program or any particular other user wants to access your program
1:27
or want to edit your program if you have some mistake. At least he should come to know which commands is used for what purpose
1:34
or what particular thing you are going to do by using those particular commands
1:38
So if you want to come at the comments into a particular file or under the instruction you have to give those particular commands by using or comments by using the hash sign So for example I have added a variable that a equals to 1
1:54
So this is one of my instruction that always my A value will be 1
1:58
Suppose that I'll add some added instructions to it. That I'm adding 1 because I have all the instructions started with 1
2:07
So all the particular number started with 1. So that you can add some commands
2:12
the person who is going to access my file or my program will come to know why I have added only one
2:17
but not the other numbers. So that means you are going to add the description
2:21
to each and every instructions. That again, if you follow, that will be better for you
2:26
as well as the other users who are going to access this particular program
2:31
The next we have that is the conditional test. Now, if I'm talking about the huge program
2:36
so as I said, A equals to one is a single line of instruction
2:40
If I have multiple instructions, of it like A and then I define the B value I have multiplied it I have divided it I have
2:47
subtracted it so I have a huge problem I have created a calculator so if this kind of programs
2:53
are there there will be different kind of conditions so if you're having different kind
2:57
of conditions you have different kinds of course into it like loopings like if else
3:02
condition there will be many things so you should know what kind of conditions and how
3:07
you're going to write the program first decide which kind of loops you will be using
3:12
or which kind of conditions you'll be using. We have different kind of loops, different kind of condition
3:17
We are going to see level. In short, I can say you should plan how you are going to write your program so that it provides
3:23
you a better output. And next once you have done with your program then you should always store it with dot SH file because SH file is your shell script file If you run by using SSH it will create an automated file for your script
3:42
So all this script file has an extension called as such. So let us begin with how we are going to create a basic program into our Linux
3:51
So let's begin with your terminal now. For starting with your basic shell programming, we should start the file
3:59
by creating the file with the VI itself or we can directly create a touch file, no issues
4:05
So I'll be creating a touch file. So if you create a touch file, just the name of the file, you need to define
4:12
Like I'm going to create a sample file of your basic programming
4:16
Along with that, you need to add the extension S-H. Once you have added it, now there is nothing in a file
4:22
I want to add it or edit this particular file. We can go for sample
4:26
dot as such and now we are going to write something. Now very first I will move into the
4:32
insertion mode and I am going to write as echo. Echo means whatever you want to
4:40
rent so that will be the echo so I'm going to define first name. And for
4:56
first name I'm going to read the first name. So you can enter the first name in a variable called as A
5:02
So whatever the value are going to insert here, it will take under the A. So it will accept that the variable A
5:08
So we can also add the comment variable A is for adding a name value in text format
5:30
So whatever the message you want to define or you know what is a description you want to define, you can define into the hash
5:39
And post that I want to just accept this value and I want to build this value
5:46
to view this value. So for weaving this value we have dollar and the variable we need to define
5:53
So I can define it as echo, hello, and it should display the name of that value. Okay. So once we
6:07
have done with that, I'll just save it. WQ, enter, and I'm going to run the same
6:16
So it's asking me for my name, so I'm going to define as trainer
6:21
So it will give you a message, hello trainer. So this is how generally we create a small sample file
6:27
So we have seen, or we have added some, you know, description about the variable into the SHFIR
6:34
but we are not able to see that when we are getting the file run
6:39
So this is hash markments that is not going to run and the, you know, the file name should always be a file
6:45
should always be SH and we are going to run this file you should use it as Satch sample
6:50
Shing so this is how we have created a basic shell scripting file and we have seen how we can get started
6:57
so in today our videos we are going to see doing all the particular programming and you know
7:02
creating loops and creating variables into this particular shell itself so for that keep watching
#Programming
#Scripting Languages