Last option or how to assign a value to a variable is by using command substitution.
Here we are storing output of system command into variable and we have to raise how to do that.
First one is by using a dollar sign and command enclosed in brackets.
Second one is to enclose system command into Bedworth apostrophes.
Now let's write some script to practice this option.
I will create a script called command SOP's that as I age
on the first line start to beat shoving
bin bash.
Well that's great variable called current directory
and assigned to it.
Output of BW D.
C'mon
on the next line we can print
script is
I'm from do our sign current directory
now save the file and video editor you need to change is a good promotion.
And now we can get on descript
and it works it out.
Script is where I'm from and the location from which the script was set I'm.
Now let's change the script a little bit.
We will get rid of parents issues and instead we will use Beckford apostrophe's which is another option
to save Gaumont output to a variable saving defile
and that AMIN
Yes the result is same as in previous example.
Great.
The great command substitution example from the real world can be time measurement.
Sometimes my want to know how much time is taken by some section of commands.
So let's make such a script.
Starting with siobhán bin bash then we can for better readability type command start time measurement
from here.
Now this will store Unix time into variable standard.
And of course we need to use command substitution here by opening bus percentage as to date command
we are converting date into a unique Styne.
If you don't know what Unix time is it is a system for describing a point in time defined as the numbers
of seconds that have elapsed since first January 1970.
What is most important here that is represented by one number.
So we can easily do difference between two unique stion we can again start output of P.W. the command
into a variable called current directory.
But because this command won't take much time we can use command sleep which will make sure that program
will be paused for specific time of seconds.
In our case two seconds.
Now we can create a variable called end and start next time.
And also
now but stype some command and time measurement
that's also great variable cost difference and store in it.
The difference between end and start don't pay much attention on how to do.
With variables.
Just do the same as me will cover of met in bash in another section.
Pay attention to that spaces between parentheses and variables.
Now we can write time elapsed
and print the output the value of different rebel
so scrip is dumb.
We can save it.
And we can
is good permission for that file.
And Danny
great we can see time lapse 2 seconds.
Amazing.
In the same way you can easily measure how much time does it take to copy all files of some directory
into another location.
You would just replace the sleep command we have just used as example with command for copying files.