Linux - Introduction Shell Substitution
Show More Show Less View Video Transcript
0:00
now in this video we are going to talk
0:02
about the shell substitution now what is
0:05
substitution now we can run some of
0:08
these shell commands into our program or
0:10
into our any of the back console or we
0:13
can say into our prompt of your any
0:15
terminal and we can substitute any
0:18
particular command of shell into a echo
0:20
command so that we can get at the output
0:22
into it all we can substitute this
0:25
particular commands output to a
0:27
particular program as well so basically
0:30
we can say this cell substitution is
0:32
nothing but we are going to substitute
0:33
the shell commands into a particular
0:36
program so you can see the command
0:38
substitution means nothing more but to
0:41
run a shell commands and store its
0:44
output into a particular variable or
0:46
into an echo command so that we can get
0:49
the output the second we have the syntax
0:52
how we'll be using this particular
0:54
commands or how we'll be using the
0:56
substitution of your commands into this
0:58
shell so just we need to define the
1:00
command name or we can define the dollar
1:03
sign along with the command name so that
1:05
we can substitute into a particular
1:07
variable so this is what the command
1:09
substitution is now let's see how we can
1:12
use this command substitution into our
1:14
Linux terminal now a clean we helped you
1:18
know most of the commands which we can
1:20
substitute into this shell itself so let
1:22
us check this is stage I can even
1:24
substitute the date as son variable into
1:27
this year same way we can also use the
1:29
command Who am I or we can use who who
1:32
has logged in into different terminals
1:34
so this or any commands I mean whatever
1:36
they generally ish you know the terminal
1:38
commands we use we can add into the
1:41
shell as well so let us like how we can
1:43
substitute a command into a shell so
1:48
substitution is the name I am going to
1:51
define for this file and I'm going to
1:55
substitute a command know for example
1:56
I'll go and add mmm DT that is a
2:01
variable I'm going to add and I'm going
2:03
to add date into it
2:07
Eco date is our the variable DT let us
2:15
check
2:18
as such substitution so I can see now we
2:22
are able to City date correct so I can
2:26
also add more of the commands into it
2:31
current date is Gigi okay and always
2:40
remember that your Akane I'm not going
2:42
to use that single quote it's quite
2:46
amusing ts and great grave that symbol
2:49
so a son grave is again below your third
2:53
symbol so the next way the user it or we
2:57
can say the command which I can
2:58
substitute into this shell can be any
3:01
common like I want to check users who
3:03
has locked in okay so I can you've users
3:07
and then I can give it a come on again
3:10
into the same s and great symbol and I'm
3:12
gonna cook you who once you have done
3:15
with the who again I can give come on
3:19
list of login users on terminals right
3:29
so we can add this one we can also give
3:33
your time commands you know uptime
3:36
commands of your system so we can say we
3:39
I'm going to define the command called
3:41
as u P that is uptime or you can also
3:44
give UT any variable because uptime is a
3:47
by default to come on so I'm not going
3:49
to use up time so we can define the date
3:52
into it and along with the date we also
3:55
should know at what time we have locked
4:00
him so what I'll be doing is I'll define
4:02
date again I'll define thee
4:06
today's uptime done with that again HECO
4:11
so the login date and time was and I'm
4:22
going to define thee
4:25
YouTube's variable done with that save
4:29
it as such and I'm going to check for T
4:33
substitution not exist so you can see
4:35
current data this list of login users
4:39
okay so in the terminal I have not
4:43
defined the command into it sorry and
4:45
then the date and when we have logged an
4:48
so I just showing you the average time
4:50
the number of users Andy when we have
4:52
loaded with this so just I need to
4:54
modify it so that we can also get the
4:56
list of users so for that I haven't
5:00
defined the list of user into terminal
5:02
so I'll just raise my variable here so
5:06
for that I just define dollar
5:11
losers done with it again will run as
5:16
such substitutions and you can check it
5:19
is also showing you the number of users
5:21
has locked and into different terminal
5:23
and the log on date and time ran your
5:25
current date and time right so this is
5:29
what exactly we have seen how we can
5:31
substitute commands into a particular
5:33
variables even we can create a simple
5:35
[Music]
5:36
sample we can say a variable list or we
5:40
can say sample batch file kind of
5:43
okay and I can list the number of
5:46
commands if I do not want it to be added
5:48
into the commands so I can put a
5:50
sequence of no commands here like LS who
5:56
Who am I correct so I can save this and
6:02
once I run this father
6:06
can see all this particular commands
6:09
will get run automatically even though
6:10
if you have it we haven't added into the
6:12
variable so we can also use the commands
6:15
into these shells that bring files so
6:17
that whenever you run this particular
6:19
script all the commands should get run
6:21
so this is what we have talked about how
6:24
we can substitute a particular command
6:26
into the shells into later videos I am
6:29
going to explore more about your voting
6:32
mechanism so for that watch the next
6:35
video
#Programming
#Programming
#Education
#Scripting Languages

