1
00:00:01,360 --> 00:00:07,800
Last option or how to assign a value to a variable is by using command substitution.

2
00:00:07,800 --> 00:00:14,280
Here we are storing output of system command into variable and we have to raise how to do that.

3
00:00:14,290 --> 00:00:20,350
First one is by using a dollar sign and command enclosed in brackets.

4
00:00:20,350 --> 00:00:26,370
Second one is to enclose system command into Bedworth apostrophes.

5
00:00:26,380 --> 00:00:29,880
Now let's write some script to practice this option.

6
00:00:33,600 --> 00:00:39,840
I will create a script called command SOP's that as I age

7
00:00:45,210 --> 00:00:48,020
on the first line start to beat shoving

8
00:00:50,590 --> 00:00:54,010
bin bash.

9
00:00:54,550 --> 00:00:58,600
Well that's great variable called current directory

10
00:01:01,080 --> 00:01:02,390
and assigned to it.

11
00:01:02,430 --> 00:01:05,060
Output of BW D.

12
00:01:05,110 --> 00:01:05,790
C'mon

13
00:01:09,210 --> 00:01:11,630
on the next line we can print

14
00:01:15,500 --> 00:01:16,740
script is

15
00:01:20,230 --> 00:01:25,290
I'm from do our sign current directory

16
00:01:32,300 --> 00:01:43,590
now save the file and video editor you need to change is a good promotion.

17
00:01:44,140 --> 00:01:45,490
And now we can get on descript

18
00:01:49,220 --> 00:01:50,170
and it works it out.

19
00:01:50,170 --> 00:01:57,550
Script is where I'm from and the location from which the script was set I'm.

20
00:01:57,850 --> 00:02:01,850
Now let's change the script a little bit.

21
00:02:02,010 --> 00:02:12,760
We will get rid of parents issues and instead we will use Beckford apostrophe's which is another option

22
00:02:13,030 --> 00:02:18,980
to save Gaumont output to a variable saving defile

23
00:02:23,780 --> 00:02:24,580
and that AMIN

24
00:02:27,880 --> 00:02:32,700
Yes the result is same as in previous example.

25
00:02:32,760 --> 00:02:33,230
Great.

26
00:02:35,030 --> 00:02:41,120
The great command substitution example from the real world can be time measurement.

27
00:02:41,150 --> 00:02:46,830
Sometimes my want to know how much time is taken by some section of commands.

28
00:02:46,970 --> 00:02:49,860
So let's make such a script.

29
00:02:50,570 --> 00:03:03,650
Starting with siobhán bin bash then we can for better readability type command start time measurement

30
00:03:08,630 --> 00:03:10,690
from here.

31
00:03:11,600 --> 00:03:16,010
Now this will store Unix time into variable standard.

32
00:03:16,550 --> 00:03:24,630
And of course we need to use command substitution here by opening bus percentage as to date command

33
00:03:25,270 --> 00:03:29,380
we are converting date into a unique Styne.

34
00:03:29,630 --> 00:03:37,280
If you don't know what Unix time is it is a system for describing a point in time defined as the numbers

35
00:03:37,280 --> 00:03:42,750
of seconds that have elapsed since first January 1970.

36
00:03:43,250 --> 00:03:48,410
What is most important here that is represented by one number.

37
00:03:48,500 --> 00:03:57,760
So we can easily do difference between two unique stion we can again start output of P.W. the command

38
00:03:58,000 --> 00:04:08,460
into a variable called current directory.

39
00:04:09,540 --> 00:04:17,800
But because this command won't take much time we can use command sleep which will make sure that program

40
00:04:17,880 --> 00:04:21,440
will be paused for specific time of seconds.

41
00:04:21,510 --> 00:04:24,640
In our case two seconds.

42
00:04:25,620 --> 00:04:31,780
Now we can create a variable called end and start next time.

43
00:04:31,820 --> 00:04:32,550
And also

44
00:04:42,220 --> 00:04:49,470
now but stype some command and time measurement

45
00:04:54,330 --> 00:04:59,140
that's also great variable cost difference and store in it.

46
00:04:59,150 --> 00:05:05,470
The difference between end and start don't pay much attention on how to do.

47
00:05:05,640 --> 00:05:06,980
With variables.

48
00:05:07,300 --> 00:05:13,410
Just do the same as me will cover of met in bash in another section.

49
00:05:20,580 --> 00:05:29,650
Pay attention to that spaces between parentheses and variables.

50
00:05:29,770 --> 00:05:34,690
Now we can write time elapsed

51
00:05:39,680 --> 00:05:44,370
and print the output the value of different rebel

52
00:05:50,070 --> 00:05:51,900
so scrip is dumb.

53
00:05:51,970 --> 00:05:53,060
We can save it.

54
00:05:56,620 --> 00:05:57,310
And we can

55
00:06:03,000 --> 00:06:06,340
is good permission for that file.

56
00:06:10,540 --> 00:06:11,160
And Danny

57
00:06:16,760 --> 00:06:21,000
great we can see time lapse 2 seconds.

58
00:06:21,230 --> 00:06:22,570
Amazing.

59
00:06:23,120 --> 00:06:29,450
In the same way you can easily measure how much time does it take to copy all files of some directory

60
00:06:29,720 --> 00:06:31,490
into another location.

61
00:06:31,700 --> 00:06:38,630
You would just replace the sleep command we have just used as example with command for copying files.
