1
00:00:04,420 --> 00:00:07,210
In this lecture I want to talk about environment variables.

2
00:00:07,240 --> 00:00:13,270
Environment variable is simply variable that is available during the entire session in the shell.

3
00:00:13,420 --> 00:00:17,800
And you could use environment variables, for example, in shell scripts.

4
00:00:17,830 --> 00:00:22,660
Also, environment variables like path are used by system itself.

5
00:00:23,280 --> 00:00:28,530
If you want to get a list of all environment variables that were set, you could simply type command

6
00:00:28,560 --> 00:00:33,750
env three letters and you'll see a set of key value pairs.

7
00:00:33,780 --> 00:00:34,380
Here.

8
00:00:34,380 --> 00:00:40,770
On the left you see name of the variable like term user terminal version and so on.

9
00:00:40,770 --> 00:00:45,930
And after equal sign you see value for a specific variable.

10
00:00:45,960 --> 00:00:52,710
For example, here you see variable name like terminal and its value is iterm2.

11
00:00:52,800 --> 00:01:01,230
Here if you scroll a bit up, you'll see variable called LS colors and its value is set here.

12
00:01:01,890 --> 00:01:07,830
Also here you see such variable as WD and it is set to slash root.

13
00:01:07,860 --> 00:01:12,270
You see such variable as shell and it is set to bin bash.

14
00:01:12,930 --> 00:01:19,010
Now I'm logged in via SSH to Docker container as root user.

15
00:01:19,020 --> 00:01:26,410
Let's now try to open up new SSH session as Bogdan User recap that I have created a new user before

16
00:01:26,410 --> 00:01:30,880
and if you have not done it, please create a new user with any username.

17
00:01:31,000 --> 00:01:33,910
And here let's use again SSH command.

18
00:01:33,940 --> 00:01:36,610
I'll use same port 2222.

19
00:01:36,640 --> 00:01:42,910
It is exposed port for docker container and here will be username Bogdan at localhost.

20
00:01:42,940 --> 00:01:43,720
Like this.

21
00:01:44,170 --> 00:01:49,200
Let's enter password for Bogdan it is 123 in my case and I'm in.

22
00:01:49,210 --> 00:01:56,290
Let's now enter in the command here and now I'll see a set of similar env variables.

23
00:01:56,320 --> 00:02:02,620
Let's quickly go back to this tab where I have entered the same command for root user and let's compare

24
00:02:02,620 --> 00:02:03,850
those outputs.

25
00:02:03,880 --> 00:02:10,120
Here is output for root user and for example here you see environment variable user that is equal to

26
00:02:10,120 --> 00:02:10,570
root.

27
00:02:10,570 --> 00:02:18,250
But if I switch to this tab, I'll see that user is set to Bogdan And also here you see different SSH

28
00:02:18,250 --> 00:02:19,660
connection variable.

29
00:02:20,470 --> 00:02:24,670
Here in this case, you see port three, five, five, nine, eight.

30
00:02:24,670 --> 00:02:29,830
And here in this case, you see another port, three, five, five, seven, eight.

31
00:02:30,760 --> 00:02:38,030
Because here are two different sessions and actually same information you see here on this line as a

32
00:02:38,410 --> 00:02:39,100
client.

33
00:02:39,650 --> 00:02:46,670
If I go back to another tab where I have logged in directly to the container this tab and enter in the

34
00:02:46,700 --> 00:02:54,410
variable, I will not see such variables as I see here as a client and as a connection.

35
00:02:54,800 --> 00:03:02,780
And that proves that set of environment variables is created when specific user logs into the system.

36
00:03:03,020 --> 00:03:08,510
And depending on the conditions, logging conditions, those sets will be different.

37
00:03:09,560 --> 00:03:10,190
All right.

38
00:03:10,220 --> 00:03:12,350
That is a set of environment variables.

39
00:03:12,380 --> 00:03:15,980
Now, question how we could access any variable.

40
00:03:15,980 --> 00:03:17,060
It is very simple.

41
00:03:17,060 --> 00:03:18,280
We have done that before.

42
00:03:18,290 --> 00:03:23,740
Let's clear terminal here and simply enter echo dollar sign path, for example.

43
00:03:23,750 --> 00:03:27,530
And here I get value for path variable.

44
00:03:28,470 --> 00:03:36,630
And now let's try to get other variable, let's say user dollar sign user, and I get value for another

45
00:03:36,630 --> 00:03:37,650
variable user.

46
00:03:37,650 --> 00:03:43,770
It is very simple and of course you could use variables in shell scripts, for example, in order to

47
00:03:43,770 --> 00:03:45,540
access some values.

48
00:03:45,540 --> 00:03:49,200
And also you could set additional variables if you want.

49
00:03:49,230 --> 00:03:57,090
For that you need to use command export and after export will be name of new variable or existing variable.

50
00:03:57,090 --> 00:04:00,540
And next comes equal sign and value for the variable.

51
00:04:00,540 --> 00:04:06,930
For example, let's create new variable called my underscore new variable like this.

52
00:04:06,930 --> 00:04:11,460
And let's set it equal to simply test like this.

53
00:04:11,490 --> 00:04:12,690
Let's press enter.

54
00:04:12,690 --> 00:04:15,060
And now let's list all variables.

55
00:04:15,060 --> 00:04:23,010
And actually, if you want, you could use here grep and here will be my let's say new like this and

56
00:04:23,010 --> 00:04:26,250
I'll get value for my new variable.

57
00:04:26,340 --> 00:04:29,080
It is actually available also in this output.

58
00:04:29,080 --> 00:04:32,620
Let me scroll a bit up and yes, here is this variable.

59
00:04:32,650 --> 00:04:35,740
My new variable and its value is test.

60
00:04:35,740 --> 00:04:39,400
And of course now you could easily access this new variable.

61
00:04:39,400 --> 00:04:45,430
Let me clear terminal echo dollar sign my new variable and here is its value.

62
00:04:45,580 --> 00:04:47,020
That is that simple.

63
00:04:47,500 --> 00:04:54,490
Also, when you run some applications like for example, Node.js, Python, Java applications, many

64
00:04:54,490 --> 00:05:02,080
applications require runtime variables and usually you could set such environment variables before start

65
00:05:02,080 --> 00:05:05,110
of any application using similar approach.

66
00:05:05,620 --> 00:05:08,530
All right, that's all about environment variables.

67
00:05:08,530 --> 00:05:11,110
And now you'll get small challenge.

68
00:05:14,930 --> 00:05:20,900
You need to create a new variable called my name my underscore name.

69
00:05:21,320 --> 00:05:27,560
Afterwards, you need to create a new shell script called name Dot as H.

70
00:05:28,100 --> 00:05:34,250
And inside of this new script you need to print your name to the terminal using Echo command.

71
00:05:34,250 --> 00:05:37,300
And afterwards, of course, you need to execute this script.

72
00:05:37,520 --> 00:05:38,480
Wish you good luck guys.

73
00:05:38,480 --> 00:05:41,060
And after the post I'll show you a solution for this challenge.

74
00:05:41,070 --> 00:05:41,870
I'll see you next.

75
00:05:41,870 --> 00:05:42,440
Bye.

