 Hello everyone. In this video we'll be discussing about the use of arrays in shell scripting. Here is the learning outcome. By the end of this session students will be able to apply the concept of arrays in shell scripts. So first of all we'll be discussing about what are variables and then recall some of the basic definitions of arrays from other programming languages. Then I'll show you the demonstration. So it's a good moment now to discuss about what is meant by an array in any programming language. You can pause the video for a while and then think on it and then resume the video. So basically an array is nothing but a subset. So an array is nothing but a collection of similar data types as you can see here. So there are six array elements which are sitting side by side as shown in the block diagram here and whatever values that are displayed in the form of indices here is generally referred as either index or the address of this particular array. So array is basically a collection of common data types which are held together so that you need not to define individual variables for storing individual data. The things will be more clear when we get into the demonstration. So let us get started with the basic block diagram of Unix system. So as you're able to see on the screen basically we have hardware here. So the PC or the computer or the CPU which we have seen earlier in the previous slide is going to rely somewhere here under the hardware block which is overlapped by something known as a kernel. So kernel is nothing but the core what we can call a system or the core course of this particular operating system. So hardware is overlapped by a kernel. So this kernel is nothing but a sort of software layer which is installed onto your hardware and which is then controlled by another layer called shell. So as you can see there are a variety of shell available in the Unix environment. So we will be generally calling it a shell. So shell will be acting as a bridge between the outer application layer and the inner hardware layer. So this is the drop structure like we have level number one, two, three and four. So level number one is the core hardware like maybe a CPU or some sort of PC on which we're installing an operating system. So the operating system has kernel which has a direct linkage with the hardware. And then this kernel can be communicating with applications like either maybe of a Gmail or it would be an FTP server or it would be any word or a text editor. So these text editors are nothing but those are the application layers which can be generally accessed by the users. So keeping this architecture or so called the block diagram of a Unix operating system we have seen that there is a shell in between the kernel and the application layer. So if you have this knowledge of how to access the hardware maybe you are connecting some sort of USB drives to your USB port on a computer and then you want to access it. You need to access it through an application then probably you should be capable enough to write a shell program to write a command which would access the definite hardware which you're interested in. So this is quite possible if you are known to this basic block diagram of Unix system. So I have logged in into the Ubuntu operating system then let me first of all open the terminal and then let us first of all log in with the root password and then let me make a new folder called 3. I'm entering into this folder and let me list down. So currently there is no content available in this particular folder. So today we'll be discussing about arrays. Let me show you exactly how the things happen. So let us quickly define a new shell file called array.sh. So as usual we are going to type the shebang first then I'll be first of all showing you the difference between variables and arrays. So for instance if I'm defining a variable with a name called name 0 1 where I'm storing the data called 1 in the text format. Similarly I'm writing name 2 defined for storing a text called 2 and then I define the last variable which holds a data called 3. Now I can access any of the individual data by using a sign called dollar. So for instance say name 0 1. So we can expect here that whenever I execute this it will show me one displayed on the screen. So before that let me make it executable then if I execute this yes. So as you're able to see I have echoed only the content of name 1. But for instance if I want to display the contents of each and every variable then it is going to be a little bit difficult. So currently the thing is that I only have three variables but in case if I'm having more than 10 and hundreds and thousands of variables then probably it is going to be the toughest part to write the same statement again and again and that becomes a little bit inappropriate in programming language perspective. So definitely we need to find a way of doing the things in a different way. So what I'll do is I'll define only a single variable so the variable name is going to be name but now I'm putting square braces here which is similar to other programming languages like Java and C and C++. So I have only single variable whereas I'm trying to refer the array sub positions with the help of their index values like we have seen in our slide earlier. So currently name of zero holds one, name of one holds two and name of two holds three. Now I want to print the same value called one similar to the output which we have printed earlier. So I'm simply writing dollar name at the index of zero. I've saved it and let me execute it and see what output I'm getting. So it is currently displaying one of zero. Okay so it's meaning that we need not to write anything like this. So if you execute this yes so this is the proper syntax of defining an array initializing it and then you can directly execute it for displaying the output. So for instance if I want to echo all the elements together of this particular array called name then I need to put a bracket which is going to be curly brace so it will be name of everything. So generally it is like a star. Okay so I need to put the dollar here so dollar name of star has to be enclosed inside the curly braces. So now if you try to access it should display you everything. So the syntax for this is going to be so the syntax for this is going to be so here is the proper syntax you put a curly brace curly braces enclosing the name of the array and then the star and then you need to put this entire thing inside the double quotes. So that whenever you execute it will display you everything. So this is the exact way of how we can use arrays in our programming of shell scripts. So this is going to be very much beneficial like reading thousands of files available in a given directory or maybe in upcoming videos we will be able to see like you are trying to read some list which has some thousands and lakhs of entries you need to convert everything and the data needs to be held inside a specific variable. So in case if you are defining a single variable and that variable is able to only store a single data at given moment of time that is generally referred as a scalar variable. So this is how we generally identify whether a given variable holder is a scalar variable or an array. So arrays are going to be very much handy in holding the data and processing the data related aspects. Here are the references used. Thank you.