Linux - Shell arrays
894 views
Nov 28, 2024
Linux - Shell arrays
View Video Transcript
0:00
now till now we have seen how we can set
0:02
the variables for into our program
0:04
different types of variable how we can
0:07
use into our shell program as well as we
0:09
have seen certain set of the
0:12
pre-existing variables which we have
0:14
that is a special variable into Linux
0:16
operating system now here we are going
0:19
to see how many kind of variable and
0:21
what the types of variables and really
0:23
will be using for creating an array of
0:26
data into a special variable or into a
0:29
particular variable that's the reason we
0:31
are going to see how we can add multiple
0:33
values into a same array called as shell
0:37
arrays so into this shell arrays we have
0:40
two type of array which we generally
0:42
create called as a scalar array and also
0:44
the array scalar variables are those
0:47
variables which can store only one data
0:50
at a time into the variable for example
0:52
a equals to 1 that is the scalar a
0:57
variable now if I'm talking about the
0:59
area of data or area of value we want to
1:02
add into a particular variable I'll be
1:04
using an array so avek equals to the
1:07
number of variables or the number of
1:09
values you want to add you can add into
1:11
the aring so let us see how we can use
1:13
or how we can add multiple values into a
1:17
particular variable into the linux shell
1:19
script things so let us begin with our
1:22
terminal now so into our previous video
1:24
we have defined a variable or an a
1:27
special kind of variable they were a
1:28
scalar variable scalar variables means
1:31
they can store only one file at a time
1:33
so let us check what we have done there
1:35
and why we are moving into the array not
1:39
as such like no we are going to define
1:41
the array values so if I take an example
1:45
I'm going to define the name as Jones
1:48
and again I'm going to define the
1:50
variable as Gerry but here the variable
1:55
is the same and the values are different
1:57
and if I define or if I check for you
2:01
know printing a particular file or the
2:04
name here by defining in such a way I'll
2:09
just save it correct
2:12
and when I run this particular file
2:15
stuff well it is just showing me during
2:17
what it will do is but we'll just ignore
2:21
the variable value you have added at the
2:25
first stage and we'll take the latest
2:28
one so that's what has pulled so but now
2:32
I want to use the same variables and I
2:35
want to add multiple values like for
2:37
example if you are schooling or if
2:39
you're in college you will win the same
2:41
standard right so the class will be seen
2:45
so if a class is same or I am going to
2:48
add multiple students into the class
2:49
same here we are going to add this
2:53
particular names of the you know people
2:56
into the name variable so for that for
3:00
adding multiple values into a variable
3:03
is called as area variable we are going
3:05
to add for that what I'm going to do is
3:08
I'll be adding just an index here
3:12
that is name and value zero same we can
3:17
add name value one right again if I want
3:22
to add more I know
3:23
names to the same variable we can use
3:26
this
3:31
we and I've defied name
3:36
and then right
3:41
and next we are going to add us for
3:45
right but there are many enough file we
3:48
have added now if I want to display this
3:51
entries and I want to know call those
3:54
names what I'll be doing is I'll be
3:55
defining it at dollar sign and name
3:59
along with the name we need to define
4:01
the index just close the bracket here so
4:05
what it will do it will print name zero
4:08
so this is how it will call your first
4:11
name or we can also use you know curly
4:15
braces here so I can also use the curly
4:19
braces like this way and here I can
4:26
this way right so it will print the
4:30
first ring I want to print the hardening
4:36
so I'll give a game the same way
4:39
forget braces name
4:42
that is is second because we are
4:45
starting from one so I want the third
4:48
name to be display let us check will
4:51
give and run the file name a video
4:54
message
4:56
it's either a certain error and he just
5:00
look where we have media okay so here I
5:05
need to close this quotations as well
5:12
let's check now as such later as a trail
5:17
showing you hello Joan and hello Ellie
5:20
so this is what how we add the area of
5:23
your different names or different values
5:26
to the same particular parameter now
5:29
whatever if I wanted to check all the
5:30
names at the time so for that I can also
5:33
give the command here I'll give the
5:37
instruction I'll be using this same
5:40
special kind of variables to display the
5:42
complete variable that I'm going to do
5:44
is in such a way echo
5:51
names equals two
5:55
list of array values I'm going to define
6:01
R comma dollar and s trick right
6:10
but dollar our next trick we are again
6:12
going to define in such a way again
6:14
we'll start dollar again we are going to
6:20
start with name into the square brackets
6:26
I'll define it this way close your curly
6:29
braces and then just correct either you
6:33
can use as trick or you can use your
6:35
address sign both walks here I cancel if
6:40
I am last Jew are they right so again
6:46
the same be
6:49
name your in spite of you know Eric I
6:53
can also define I'd rate
6:58
I'm going to close the braces and
7:02
curtisha same if I want to check for the
7:05
count of your erase
7:12
so I'll define simply color
7:18
curly braces name no value we'll just
7:23
define hash okay so let us firm this all
7:32
such peridot okay so it's not accepting
7:37
the account okay but the others are
7:39
possible so I let me remove the account
7:42
here
7:50
you
7:52
so you can check now
7:56
so we can also check for the counter
7:58
drone that they are going to see but
8:00
here now it is showing you the list of
8:01
the all the array values you have added
8:04
to it right so these are the four values
8:07
I have added starting from 0 through 3
8:10
my in the same way we can check into the
8:12
cat array dot message right so this is
8:16
our d 4 to 5 values I've added so
8:20
starting from your jones cherry sadly an
8:22
en Sony so these are the values I'm able
8:26
to display here so this is how you can
8:28
add a number of values into the same
8:31
variable forming an array so into next
8:35
video we are going to see more about
8:38
your different you know and once
8:40
programming where I'm going to show you
8:42
how you can use the operators into your
8:46
programs until now we were working on
8:48
the complete attacking text documents
8:51
now I'm going to use some numbers and
8:53
I'm going to operate door number two
8:54
years ago sorry thematical operators
#Computer Education
#Computer Science
#Other
#Programming
#Scripting Languages