 A cell script is basically a program that designed to be run by the Linux or Unix cell. Cell is basically scripting is writing a series of commands for execution on cell. Basically, it's combination of the different commands which are we do manually execution on the cell terminal. It can combine the lengthy and repetitive sequence of command into the single and simple script. It's a kind of very simple text script which can be stored and executed anytime. And this reduce the abort required by the end user. So you don't need to the run every time the same commands and doing the recall this all commands. So once you have the commands in a specific cell scripting, so you just have to the run a simple single script only. So cell is a command line interpreter. Basically, it's typically operating by the perform the cell script, include the manipulation of a program and execution and printing the text output. Basically, there are two types of cells. There's one is a bone cell and one is a C cell. Bone cell, the prompt of this bone cell is the dollar sign and it's derived listed below. So there are the three kinds of bone cell. Po 6 cell is known as the SH. Con cell is known as the SH and bone again as health also known as the base. So basically base is the most popular cell in a Linux unique systems. And we will going to deep dive the base cell in this tutorial. The second one is the C cell, the prompt for the C cell is the percentage sign. And there are two types, one is the C cell, top C and C cell. So these are known as the CSH and TCSH. And in this tutorial, we will going to deep dive and we'll see the example of the base cell, okay. So the first script of cell script, we're going to start the cell script. Basically, it's a simple plain text file which contain the series of commands. And it's a combination of command where you can run your commands over the terminal which you have to make in a simple text file where you going to the combine all these commands, okay. So there are some standard example for the name of your script. So how do you define your script name? So this is here the sum of example you're given. So there is a one is example hyphen one dot SH, example underscore. Example one, you can make combination of character. I can start with the example underscore. So it's a valid name. So let's go for the terminal and create the simple first cell script. And let's start. So here I'm creating one file. So I have already created files. So let me remove my file. So I have created and now I'm creating the new file. So basically when you want to write the script, a cell script, you need a terminal where you can write. So it's kind of editor. There are the sum of editors given by the Linux like Vi, V, Neno. You can use any of that. You can use the text editor also. Basically I'm using here the Ubuntu for my scripting example. But you can use any Linux flavor, any Linux distribution system for doing the cell because it's supported by the all Linux system. So let me create here the first script. Okay, so I'm creating my first cell script. I'm giving them my base. So I'm printing here my first script. This is my first cell script. Okay, I'm saving this one. Okay, now I want to execute this file. So you can see here this is my first cell script. Okay, and here it will give the execution output using this simple, the ss, example.sh. And one more thing you have to understand that's permission for my script is I'm showing the command ls-l, example 1.sh, okay. So here you can see the permission is set over, but I've already said that's why it's showing the permission proper way. So here the different is read write x, read write x, and read write x, it's giving the execution permission. Hello friends, in previous session we tried to understand the first script created the simple first cell script where we can print my new script. In this case, in this session we will try to understand the permission of file, how do we set the permission, and how to verify the permissions. So let's start. So you can see here the details of file permission, but before that we go to the console and we will try to understand from console. So same we have created the example 1.sh. Right now I didn't give any permission, so I'm trying to execute file, okay. So it will not allow me to the execute. So I'm setting permission, but before that let's see the actual permission for this file, okay. So you can see the permission for this file is here. It's everywhere is read write read read. So first we have to understand what is this. So for that let's go to the script. So you can see here the for the portion one is the hyphen that the first hyphen is showing that it's a directory or a file. So hyphen means it's a normal file, but in case of the it's mentioned D then it means the directory. Okay, let's move forward. So the first read write execute it's mentioned for the owner permission. So you can see the read write and execute permission for the owner. The second is the read write execution permission for the group owner. So your user for which group it's identify the permission for the specific group. The third one read write execute permission for the all other user. It means the all user available in system can use the permission set of this one. So read write executions it identify using the four to one. So one means it's a read two means write and four means execute. So you want to make a combination of threes then you can make the seven is the total execution permission read write execution for all three. So if I want to give the permission to the all for the execution read write execution I have to just mention the seven seven seven. If I want to make the permission that only owner can have the access of the file that execution then you have to make the owner set is the seven. Okay, let's move to the setting permission over here. Okay now I'm setting permission using chmode command and I'm setting the permission for execution that's a plus x and example 100 sh. Okay now let's see and let's verify the permission settings you can see the permission set is the execution word that before is the only read write. You can see the difference over here. So now execution permission set for the all user. Okay, let's try to run our files. So giving the dots less example 100 sh, sorry. Okay, so now I'm gets the my output over here. So this is my first cell script. So we have identified the permission over here. You can see one more thing is when I make the LS minus L you can see the details of the read write execution for the user group on other user but you can also identify this file is created by the which user. So this file is created by the root user and it's root user fall in the which group it's a root group. So this information you will get using the LS minus L command. So you need the settings permission and file permission is most important component in Linux and you should know the how to define. Okay, one more thing I want to explain that I want to set the read write permission read execution permission not read write but you can make your combination as per your need. So I want to give the read and execution permission. You can see, okay. Let's see. So now you can see the difference. Same way you can give the number I want to set the number is 111 and you can see the difference. So now each one have the only execution permission not read write. If I want to give the read write I can change the number to you can see the difference. This is a write and 444 let's see the difference here. So it's read. So 421, so 4 means read, 2 means write and 1 means executions. So if I want to take anything for all three just I will make the combination of 421 and give the 777. It will make the read write execution for all. Let's see, okay, got it. So friends, we will see in next session the Sibang and importance of the dots forward slash that which we have not discussed and we will see some more Linux command visit commands which use in the cell script. Hello friends, welcome to this session. We saw that the permission setting and how to manipulate the whole permission details and how to set the permission for executable file. And in this session, we will try to understand what is the importance of Sibang and why we are using the dot forward slash and we will try to start the sum of the variables in this session. So let's start. So let me show you my first script. So this is our first script and you using cat command you can see the your script. So I execute the cat example dot one SS it will show the my script content on my screen. So using vi command you can edit script. So you can edit your script but you just want to see your script you can do this example one dot SH cat, okay. So we have given the has estimation sign and bin base. So this calls the Sibang in the cell scripting which we already discussed in the first session but the importance of Sibang is the Linux system could have the multiple cells. For example, C cells, the TSL and any kind of cell but I want to use base cell. So I have to mention the base cell in my first line of proof. If I have not mentioned the same in my script script might be run but it might give the error some place at the the default cell will run. So might be I have written script the base on the base cell and the default set could be the C cell. So whether it get the mismatch for the sum of command or sum of syntax it will create the issues. So it's recommended that you want to if you want to writing the script you should write your Sibang on the default base which you want to use for your script. Okay, so next one is where we are passing the dot forward slash for executing the my script. So why I'm giving the dot forward slash? So let's try to understand dot forward slash. So dot means the present directory. So if I do the silly dot it won't do anything. So it do this it will just change the directory but the dot means the present directory. If I do the city dot dot it will do the previous directory. So it's a parent directory. So using the city dot dot it will create the parent only single dot is identify the present. So forward slash I'm giving the name of my forward slash I'm giving the name of my directories. So I again came to my directories just for showing their files. Okay, so if I want to execute my file so I just have to pass the forward slash home which is my path and my script name. So you can see the script name here is the this is my first script. So using the forward slash I can the pass but I want the present directories script. I just have to pass the dot forward slash and example one dot SH. So it will redirect the same things but when you pass the dot with the forward slash it will the passing the current directory. Okay, so let's move to the next. Let's open the file my file it's example one dot SH. Okay, so here you can see the echo command gives the return the double quote syntax and it will print. So echo is the default commands, building command of the cell. So echo written in the cell and echo works like it will print the content. So if you want to understand the echo building commands you just have to write the type echo. So it will show the echo is the cell building. Let me clear screen and go to on the top. Okay, so it will identify the echo is the cell building. Okay, so if I want to do the more information about the echo. So type minus a echo will show the details about the echo building commands. So it will show the building command but it will also show the path for the my echo commands presence. So we can use the same path for the using of the echo. So I'm just giving the example user bin echo. I want to give any example that's example. Okay, let me example print. So it will print my example context. So echo basically use for the printing the your context which pass in you double quotes. Okay, so let's move forward and create the script too for a defining variable over here. So I'm creating the example 2.sh. Sorry, I give in the one only. Okay, example 2.sh and I'm giving the C bank here. Bin dash, okay. So here I'm giving the variable is test and name. Okay, so I'm going to echo hello, mister or you can do the better way. That's I'm doing the name here and you can make it the name. This is in caps. Okay, sorry. Okay, again, we have to give the permission set ch mode plus x example 2.sh. Let's run. Okay, so hello, Mr. Vijay. So we have passed the Vijay as very, let me print here the example too. So Vijay, we have created as a variable and we print the Vijay in our echo statement. So I passed the variable using the dollar and bracket and variable name. So you have to pass this the same syntax. If you give the space anyhow, it will show the error. So you have to make sure the properly syntax followed. And I think we have done in this session is the, what is the importance of C bank, building commands and the how to define variable. In next session, we will go to understand the different context of the self scripting in context of variable using and the looping. So let's meet on next session. Hello friends, in previous session, we have understand that the basic variable configuration and how to use the variable in a script. In this session, we're going to understand the deep dive of the variable, the naming convention and the kind of how to use variable in a script, variable value of reassignment and the command of inline documents. So let's start. Okay, so, okay. So we have created two files over there and let me open my example too. Okay, so here we have used the variable name and the key and the value. So name of variable are really very important in this case. So what kind of variable name we can define? So variable name can contains the letter, digit and underscore only. Variable name cannot start with the number. So you can define your variable name with the name, means the name of your letters with digit. You can use the underscore. You can use the digit in the name of the variable but the name should not start with the digit and the name also should not contain the hyphen variable. So let me show you the valid variable. So I'm creating the new file, example 3.sh. Okay, so I'm creating the name is a variable and it's a value. Okay, eco, my name is, so what kind of variable supported? So we can configure the name. It's a valid variable, underscore one. It's also valid variable, underscore name is also valid variable but one name is invalid. One hyphen name, sorry, name hyphen one, it is also invalid. So name contains the digit and letter that's okay but name should not start with the digit. Okay, so I'm removing this example over here. Okay, so let's print this script. Okay, first we have to set the permission ch mode plus x, example 3.sh. Okay, now let's run the example 3.sh. Okay, now I'm updating the file I'm updating the file here. Sorry, I didn't give the right. Okay, so I'm updating the file and I'm just giving the name equal to James. Let me remove space here. Okay, now I'm rebinding the same statement. My name is, let's run this file and let's see what's happened. Oh, so you can see the first statement itself which is saying that my name is the Vijay. That's the first variable assignment and the second is my name is the James. It's the second variable assignment. So let's see the file here. Okay, so you can see the file itself saying that there's a first assignment is the Vijay and the next assignment is the same James. So you can see the sequence of statement will be executed in a cell script. So first statement will be executed with the name Vijay, it's do the echo and the next one it's given the name variable, given the real value. So it's taken the new value and it's again bring the new value. So this called the variable reassignment. Okay, now let's move for some more examples. Let me, let me clear first so you can see. Okay, let me open the example three dot SH. Okay, so I want to pass the variable here. If I will not give the bracket what happened? So I'm giving the my name is the my name and testing. And here I'm giving the name is testing. I'm just giving the hype on this for the differentiate the value. Okay, let's print this two statement. So it's given the prints that name Vijay testing name James testing. Let's open again pile. You can see the, it's value with the name and string it's getting quantitative. So your value is passed with the variable here and it's getting quantity. So you can use the naming, mixing with the string and your variable. So let's move for the next example. Okay, so variable three, example three and I'm removing this second. Okay, here I'm giving the name second with the small letter James. And the third one is the name equal to Peter. Okay, so I'm writing the echo statement again. Echo name, that's a small second one. Third one is echo my name is small character all. Okay, let me see a file and execute. Okay, we have made some mistake. Okay, let's see the error over here. So see what he's saying it's unexpected you are by looking for the matching and it's unexpected end of file. So it's written the first value. It's written the second value, but it's a third line, it's giving the error. So it's giving the error is here in the name. Why? So we have given the wrong parenthesis here. Let me update and let's run again. So all three name are the same, but the kids sensitiveness are different. So if you made the difference in name kids sensitive the old variable are treated as a separate. So you have to make sure the number naming should be the proper. So it's not hard coded that you should use the variable as a case sensitive capital letter, but it's recommended that you can easily identify this variable and this is the normal script. Okay, next one we are going to move for the comments. Okay, so comments normally start with the has but see bank has is only X. But see bank has is only exceptional case in this scripting, but all has will treated as a comments. So I'm creating the comment here that this is my first variable declaration. So you can make the proper line settings. So it's normally visible and easy to understand. This is my second variable declaration. You can make third one. This is third variable. Okay, now in eco we can write here print the name variable. Same way we can write here print name variable and the last one print name variable. Okay, I'm saving this one. Now we are running. So comments will make sure your documentation looks like proper and anybody can read your pile and you can understand what the script contains. So in this session we have understand the rules of the naming convention, variable, valid and invalid contains how we can identify value resendment, value resendment we have to understand and the comment in line documentation. In next session we will try to understand logical script and we'll create a logical script which normally use in a scripting. So let's meet on next session. Thank you. Hello friends. In previous session we have discussed and show that the information of name, variable name, information of definition, how to define variable, naming convention, valuable resendment and the comments. So in this session, today's session we will go to understand the kind of quite large script and we'll create to get the information of system with the host name, kernel, memory, uses and discusses. So we'll try to understand how to fetch system information and let's start. Okay. So I'm creating the new file. That's a example. 4.sh. So we have understand the importance of the comments. So we will use the comments in this script. So this script is created for getting system information. Okay. So script will start from here. So we need the host name. So here is the display system host name next. So let's display first the today's date. So display the current then display the KR kernel information. Display the memory utilization and display the disk utilization. And this end of script script completed here. So we want to use the comments over here. So this base I have created the comments. So let's start. So it easy to read for anybody. So I'm writing here the script started here. Okay. Now I want the display date. So I'm printing the date here. I want the display host name. So I want to place host name. I want to display the kernel information. So your name your name minus memory utilization free minus h means readable same way disk utilization df minus h it's a human readable script completed here eco script completed. Okay. Let's give the permission. Okay. Now let's run. Okay. So you can see the output here. The script is started here. This is the date of system. This is the host name. This is the kernel information, kernel version and system version. So at 64 bits this utilization of memory utilization and this utilization of disk you can update your script if you need to if you need more modification so you can do the eco here. So date display. So it will print the display. You can make the combination of date display also with the same statement using the plus. So friends, this is all about the script where we can identify the system info and having the some kind of the script where having the sum up kind of logical requirement. So this kind of requirement which usually come in self scripting. So this is the complete example of how to define the script and how to get the information of system. In next session we will going to discuss about the looping and how system loops help. So let's meet in next session. Hello friends. In previous session we have seen the combination of file with the different parameter which page from the Linux systems and we have received some certain configuration from the systems where kind of memory details disk utilization date details, kernel details and all these details we made a single script. So today's session we are going to focus on the condition of if loop. So let's start. So I am creating one file where I am giving the name of condition in the cbank. Okay. Now I am doing this program for integer values. So let's make a value of a equal to 10. Let's make a value of b equal to 20. Okay. Now I am comparing these two value. So you have to make sure the condition statement happened properly in if condition. So you have to make sure the syntax. So I am giving the if in a bracket $1 means a variable is equal to $b. So we are comparing this value if both are equal then what happened? So we have to write some action. So I am doing the action over here is echo same as b. If this condition is not satisfied then it will print the l statement then echo a is not b. Let's save this file and run this file. Okay. So we made one small mistake over here. So we should make sure that when we start if we have to make the end of if loop with fi. Now if loop got stopped. So this started loop this is then the action item this is else action item. So let's save again. Let's run again. So now it's showing the a is not b because both value are different. Let's change the value here. I am changing the value both are same. Now let's run. So a is same as b. So its condition is working fine. So if I want to compare negatively if not equal to then what happened? So I have to give the condition like this if a is not equal to b then a is same as b else a is not equal to b. Let's run again. This is run the condition of the loop. Let's see the loop in a different way. I want to so here we have discussed the two things that integer comparison with equals to an integer and comparison with not equals to. So let's remove this code. So let's the user which I logged in is a root or not. So I am making one user name variable and passing value who am I. I am saving this value just to show you what the who am I commands do. So who am I. So I am taking that input in user name. Now just for debug purpose I am doing the print of user name. Let's run this command so we can trace our script one by one steps. So now it's print the root user. That means our echo is working fine. Let's move again let's making the condition here. User name is equal to equal to root. If user name is matched with root then you we have to print the echo have logged in with root user as echo you are not using root. We have to complete the if statement using f I. Let's close this file and let's run. So now it's getting that you have logged in with the root user. Let's see the file. So here we have the given condition for equal to same with and not equal to we already discussed like that we can give the greater than greater than equal to so you can make the your mathematics combination with the comparison operator also so in this session we have seen that the condition with a loop we will see the more details in loop in next sessions for example for a while and the different combination of this for while with the incremental variables. Welcome back in this session we have seen the different kind of system uses for variable commands and the created script which get the information from this system. So in this session we are going to understand the follow how follow bar works in self scripting so let's start so I want to show you the follow explore in our GitHub repository so if you can see the GitHub repository that we created our different example for the self script tutorials you can see here so we have created the example 1, 2, 3, 4, 5, 6 and some special case so here I am opening the for loop so in follow we have created the three example that the first example having the condition where I am moving the I into the 1, 2, 3, 4, 5 so here with the declaration of 4 is 4 and I am starting the I as a variable and I will be run in the this variable's value then the loop start from the do and loops done from the done and in between the statement will be executed in this loop so this loop will be run the 5 times and each time it will be written the I value is 1, 2, 3, 4, 5 so the second example have given the for loop having the bracket where 1, 2, 5 is executed and again it will be written the lower I value so let's do this one in our script here so I am creating a script here that example and let's call 4.sh so here I am creating the now starting the example of forSwamp here the writing the this is 4 so here I am giving the first message where the script started now starting the for we can also give the comment so we can understand the things that's an example 1 4 done is my loop close and in between I am printing the equal example 1 dollar I means it will run the value passed from the for loop let's run this script so I am getting the example 1, 2, 3, 4, 5 now let's update the loop example 2 example 2 again dollar I closing the loop I am running the script so here also I get the 1, 2, 3, 4, 5 we can also forget the loop just with the equal so you can understand the equal so here you can start let's say I will not print it here it's part of the print so I am just removing this one now I am taking the for loop in third time just I sorry 4 I equal to 0 I greater than equal to 5 less than equal to 5 and I plus plus example 3 dollar I before that let's print the equal example 3 let's close loop and let's rerun again script and we got the 0 to 5 okay I am clearing the screen so we can understand now I am seeing the game okay so let's make the things easy to understand so I am creating the here the script started over here so yeah we missed that minus n so minus n for we have to pass the minus e option for the expression and this will work to write minus e option so now minus n will be work here I am giving the example to I am also doing the new line here but just I want to pass the one so one example once you can do only equal it will do the same things it will do the new line also equal also do the same things and in the last we will again print the equal now you can see that the script started and all new line also works using the slash n and also normally equal will be do the same thing new line so if you want to pass the new line you have to pass the minus e option for the regular expression so this is the totally example of the for loop and I hope you got the idea about how to work with the for loop welcome back in this session we have seen the different functions of shell scripting so let's have a quick recap what we have seen till now so basically we have seen the configuration for the basing how where use the base and what is the base variables how to use variable how to configure variable how to assign value and how to use the variable in a script so quick recap that variable name are contained only later a2z that's caps and small both numbers 0 to 9 and underscore only how to define variables quick note that's a variable name that's we give the variable name and variable value that's the variable definition and how to access the variable just you can access your variable using the dollar sign in your script the next one is the comment comment is the kind of documentation in your script in your programming so someone else can read your comments and can understand the program is for what so who have made the logic for what that can be understandable using your comments so comments having the two things that's a single line comment and multi line comments so single line comments can be used with the hash sign that you can see and the multi line comments that we'll use with the double less than sign so here that's given the single but it's a double less than sign and you can give the comment name and last the same name comment is the ending with the comment name so in between you can write your comment statements we have also seen the permissions file permission so there are three kind of permission for your file that's important in linux there's a owner group and others so there's three section of your permission that's the read write and execution read write and execution so you have to understand there's a number of the permission there's a one two and four so one is execution two is the write and four is the read so you can give any of the combination of these three if you want to give the for all that's the I want to give the all permission to owner and don't want to give the anything to group and others that's just have to give that say one zero zero so seven means the execution write and read zero means nothing so I want to assign the permission to owner is a full permission and group and other I don't want to give the any permission then you have to give the seven zero zero okay so I have created one simple program just recall this example you can see we are not going to execute because we already done but you can refer this program in your practical session that's so it's a really easy so you can see the the single line commands so I have given the single lines using the hairs and multi-line commands using the double less than sign so this is the example for the commenting so you can use this program in your practical session so we have done the this basic a configuration of the self-scripting in next we will try to understand some more exploring of the self-scripting commands for example looping with the while operators and many more things welcome back in this session Linux operator so basically Linux operator are mostly useful when you are writing scripting and when you are doing the operational things with Linux so in this session we are trying to understand how to use operator in a self-scripting so I have opened the script where I have written the full script in my git repo you can refer the same when you want to explore so here we will see the same example in practically in our session so I am opening the same script here so I just give the name is wildcard.sh so see I am just increasing font size here ok so here I started with the command section that is a single line command that is a again example for the command but we will move forward because we already seen the commands so here the eco I have just printed the directory created so I am creating the port directory here so you can see the make directory A make directory B make directory C and D so with the single command line I can create the directory over here now I am creating the inner directory I am creating the files here so you can see I am creating the files here in A directory I am creating the 1.txt 2.txt and 3.txt so you can see using touch I am creating the files so once all the directory are created and file are created I am checking my listing of the A directory that is how many files are available in A directory so here I am creating the LSA once this listing is done I am moving the my all files available in A directory to B directory so I am copying not moving directly so Cp A star star means all this is the actual operator of wildcard the star will copy to the all files in B so this will see the copying the file from A to B so once file are copied to the B we are checking the listing using the LSA for B so we can see the same listing in B so let's move for the next commands down okay so I copied now I check also now what I am doing I am removing the old files from the B so RM-F will be doing the removing so I am using the star it's removing again the old files from the B again we are checking the B using the LS so now we removed the old files and we are also validating the next one is we are copying again A.star.text so here I didn't give the star here I give the A.star.text so all directory having the txt extension will be all file having the txt extension will be copied to the C directory okay now again we check the C directory listing you can see here LSL okay so now our script is done let's have a run this script and we can understand how this script is behaving so now you can see here the output of here so my old directory are created I created the text file now I see the listing of the 3 now I am copying A to B so you can see the listing of B again the listing of B will be going to empty because we have removed here star now what we did we copy all star extension from A to C and this is the C listing now you can see the C listing let's have the look here you can see here the LS let's we do the C here so it will you will see the listing here that's a 1.txt, 2.txt and 3.txt you can see the same here for the A so there you can see but for B you won't see because we have removed all files so this is all about how to use the wild card in a self scripting welcome back in this session we have seen the fall loop if condition and in this section we are understanding the wild loop so wild loop is again the simplest loop where it's you can use in your scripting so how do we use the wild loop so you can see the wild loop that's a syntax is very easy that's a wild you have to give the wild and the condition so if the condition gets true it will do the command execution in between do and do so it's a really easy you can use for the wild so how we are going to use in our script so this is an example here so we have to define the variable over here using the value 0 and I am increasing that value 0 to 0 to the plus 1 and when it reach to 10 it will stop my loop so I know the condition where I want to stop my loop so that's why I am giving the condition true first so when a value is less than equal to 10 it will get stopped so here I am giving the echo dollar a that will print the a value and we are increasing the a value in plus 1 so let's create the same script in our script so I am creating here wild example.sh so defining a variable as 0 giving the condition file make sure you pass the proper space here so dollar a less than 10 do done so in between do and we will do execution our statement here that echo dollar a so we are printing here now we are increasing the a value so expression will be used for here to doing the any mathematical operation here so I am increasing my value plus 1 ok so now our value will be increasing plus 1 it will be print a value incrementally and when it reach to the 10 it will get stopped so let run this script ok so now it's started the 0 to 9 and it's loop get stopped so let's look again the syntax here so this really easy syntax you can see that's a while and give the condition and pass your commands here