1 00:00:06,630 --> 00:00:07,463 - All right. 2 00:00:07,463 --> 00:00:09,480 We have been talking about many Bash features. 3 00:00:09,480 --> 00:00:11,760 Some of these Bash features need to be provided 4 00:00:11,760 --> 00:00:13,950 as a standard solution while you boot. 5 00:00:13,950 --> 00:00:16,556 And that is why we have the Bash startup files. 6 00:00:16,556 --> 00:00:19,373 To start with, Bash defines that you can use 7 00:00:19,373 --> 00:00:22,449 etc environment to contain a list of variables. 8 00:00:22,449 --> 00:00:25,353 And this etc environment is the first file 9 00:00:25,353 --> 00:00:28,560 that is processed while starting a Bash shell. 10 00:00:28,560 --> 00:00:31,830 Notice that using etc environment is not mandatory 11 00:00:31,830 --> 00:00:34,020 so you might miss it on your distribution, 12 00:00:34,020 --> 00:00:35,580 which is the case on Red Hat. 13 00:00:35,580 --> 00:00:38,929 Red Hat and family doesn't use etc environment. 14 00:00:38,929 --> 00:00:41,670 Then we have etc profile. 15 00:00:41,670 --> 00:00:45,570 Etc profile is very important startup script. 16 00:00:45,570 --> 00:00:47,850 It is executed while users are logging in. 17 00:00:47,850 --> 00:00:49,980 An etc profile works 18 00:00:49,980 --> 00:00:53,703 with drop in directly etc profile dot D. 19 00:00:54,570 --> 00:00:58,980 So in etc profile dot D you can enter any script 20 00:00:58,980 --> 00:01:01,923 that will be included as a part of the etc profile. 21 00:01:02,790 --> 00:01:06,360 And users can have their specific etc profile as well. 22 00:01:06,360 --> 00:01:07,950 And that makes sense, because sometimes 23 00:01:07,950 --> 00:01:09,270 you want to make sure that the setting 24 00:01:09,270 --> 00:01:11,640 is only available for a specific user, 25 00:01:11,640 --> 00:01:12,870 not for everybody. 26 00:01:12,870 --> 00:01:14,700 Well, in that case, you make sure 27 00:01:14,700 --> 00:01:17,250 that the user has a Bash underscore profile 28 00:01:17,250 --> 00:01:18,750 and that will be processed 29 00:01:18,750 --> 00:01:21,570 anytime the user is logging in. 30 00:01:21,570 --> 00:01:23,790 And you can even create a logout file. 31 00:01:23,790 --> 00:01:25,950 Dot Bash underscore logout. 32 00:01:25,950 --> 00:01:27,840 That is where you are going to process 33 00:01:27,840 --> 00:01:29,820 when a user logs out. 34 00:01:29,820 --> 00:01:32,520 Logs out, that means that the user is typing exit 35 00:01:32,520 --> 00:01:34,650 from a current shell session. 36 00:01:34,650 --> 00:01:37,600 And the Bash underscore logout is an awesome command to 37 00:01:37,600 --> 00:01:40,383 take care of cleanup, for instance. 38 00:01:41,340 --> 00:01:45,338 Now closely related to etc profile is etc Bash RC. 39 00:01:45,338 --> 00:01:50,185 Etc Bash RC is processed every time a subshell is started. 40 00:01:50,185 --> 00:01:54,930 It can have a user specific dot Bash RC as well. 41 00:01:54,930 --> 00:01:57,210 And you might wonder why do we need two files? 42 00:01:57,210 --> 00:01:58,950 Why is one not enough? 43 00:01:58,950 --> 00:02:01,500 Well, that is because in a login shell where 44 00:02:01,500 --> 00:02:04,871 the user first authorizes and authenticates 45 00:02:04,871 --> 00:02:07,560 you might want to do different things than 46 00:02:07,560 --> 00:02:10,770 in a subshell where we already know about these users. 47 00:02:10,770 --> 00:02:13,631 And that is why there is two of them. But you will notice 48 00:02:13,631 --> 00:02:18,360 that on many Linux distributions, they are kind of the same. 49 00:02:18,360 --> 00:02:20,610 Now let me demonstrate how this works 50 00:02:20,610 --> 00:02:21,813 and how we can use them. 51 00:02:23,970 --> 00:02:27,960 So I'm starting with pseudo vim etc profile. 52 00:02:27,960 --> 00:02:30,840 Strictly, you don't really need pseudo to read file 53 00:02:30,840 --> 00:02:33,240 but it's making it a little bit easier 54 00:02:33,240 --> 00:02:34,770 if you want to modify. 55 00:02:34,770 --> 00:02:37,380 And there, we can see shell scripting code. 56 00:02:37,380 --> 00:02:39,630 This is shell scripting code, and I can only 57 00:02:39,630 --> 00:02:41,169 tell you one thing about it. 58 00:02:41,169 --> 00:02:42,840 Don't touch it. 59 00:02:42,840 --> 00:02:44,222 Don't change it. 60 00:02:44,222 --> 00:02:46,830 Even if there's a parameter where you think, hey 61 00:02:46,830 --> 00:02:50,100 I want to change that, you better don't change it here 62 00:02:50,100 --> 00:02:52,650 because etc profile is managed. 63 00:02:52,650 --> 00:02:54,330 It's a managed file, so it might 64 00:02:54,330 --> 00:02:56,940 get updated automatically. 65 00:02:56,940 --> 00:03:01,940 Let me do a pseudo LS on etc profile dot D. 66 00:03:02,760 --> 00:03:05,250 And there we can see the drop in files. 67 00:03:05,250 --> 00:03:08,624 These are shell scripts and these shell scripts are edited 68 00:03:08,624 --> 00:03:12,480 to, as in addition to etc profile. 69 00:03:12,480 --> 00:03:15,926 So if I wanted to change my Bash history file size 70 00:03:15,926 --> 00:03:20,926 for everybody, I can use pseudo vim etc profile dot D 71 00:03:24,390 --> 00:03:29,390 slash history dot SH. The file needs to end in SH 72 00:03:30,240 --> 00:03:31,380 and in case you're wondering 73 00:03:31,380 --> 00:03:36,380 what is this dot CSH? Well dot CSH is for the C shell. 74 00:03:37,050 --> 00:03:39,210 That's a different shell that is not very 75 00:03:39,210 --> 00:03:41,070 commonly used anymore. 76 00:03:41,070 --> 00:03:44,520 So I'm just using SH to define a Bash include, 77 00:03:44,520 --> 00:03:46,140 in which I use 78 00:03:46,140 --> 00:03:50,650 export HISTSIZE is 2,500 79 00:03:52,590 --> 00:03:54,971 and export 80 00:03:54,971 --> 00:03:59,971 HISTFILESIZE is 5,000 for instance. 81 00:04:01,050 --> 00:04:02,220 And there we go. 82 00:04:02,220 --> 00:04:04,800 Now, the thing is that I just changed 83 00:04:04,800 --> 00:04:06,390 my history dot SH. 84 00:04:06,390 --> 00:04:09,300 Do you think that is automatically going to work? 85 00:04:09,300 --> 00:04:10,890 Well, I can tell you a secret. 86 00:04:10,890 --> 00:04:14,910 It's not because this is etc profile and etc profile 87 00:04:14,910 --> 00:04:16,860 is all about logging in. 88 00:04:16,860 --> 00:04:19,390 So if I use my HISTSIZE 89 00:04:21,238 --> 00:04:24,150 variable to check what we've got 90 00:04:24,150 --> 00:04:27,843 we can see my, HISTSIZE is currently set to 1,000. 91 00:04:28,890 --> 00:04:31,140 There are two ways to make sure 92 00:04:31,140 --> 00:04:33,810 that the new settings are going to be effective. 93 00:04:33,810 --> 00:04:37,020 One way is to log out, log in again. 94 00:04:37,020 --> 00:04:39,090 The other way is kind of a shortcut 95 00:04:39,090 --> 00:04:42,450 and that is where you are going to use source. 96 00:04:42,450 --> 00:04:47,450 Source on etc profile dot D slash history dot SH. 97 00:04:49,860 --> 00:04:52,560 And now, if I use my echo HISTSIZE again, 98 00:04:52,560 --> 00:04:55,320 there you go set to 2,500. 99 00:04:55,320 --> 00:04:57,810 Which is by the way, pretty useful if you are 100 00:04:57,810 --> 00:05:00,030 planning to use a lot of complex commands 101 00:05:00,030 --> 00:05:01,830 and you wanna be able to find them again 102 00:05:01,830 --> 00:05:04,200 even a year from now. 103 00:05:04,200 --> 00:05:07,473 Right, let me have a look at one more file. 104 00:05:08,580 --> 00:05:11,700 And that is what you can put in your home directory. 105 00:05:11,700 --> 00:05:14,357 So Bash profile. And what is that doing? 106 00:05:14,357 --> 00:05:16,740 Well, this is shell scripting code. 107 00:05:16,740 --> 00:05:19,710 And in this shell scripting code, we are using a 108 00:05:19,710 --> 00:05:21,431 IF statement to test, if we have a file 109 00:05:21,431 --> 00:05:24,390 with the name dot Bash RC. 110 00:05:24,390 --> 00:05:25,860 Now, what are we going to do? 111 00:05:25,860 --> 00:05:29,070 We are going to read the file dot Bash RC. 112 00:05:29,070 --> 00:05:31,830 And that is just to illustrate that Bash profile 113 00:05:31,830 --> 00:05:35,940 and Bash RC are pretty close to one another. 114 00:05:35,940 --> 00:05:37,950 So what do we have in Bash RC? 115 00:05:37,950 --> 00:05:40,680 Well, in Bash RC, we have all this stuff that is 116 00:05:40,680 --> 00:05:43,020 for this specific user. 117 00:05:43,020 --> 00:05:47,020 So if this specific user needs to have a variable 118 00:05:47,955 --> 00:05:51,990 export color is blue, for instance. 119 00:05:51,990 --> 00:05:55,950 You put it in the Bash RC. Bash RC is for subshells. 120 00:05:55,950 --> 00:05:59,070 So I am going to use Bash 121 00:05:59,070 --> 00:06:01,620 and I'm going to use echo dollar color 122 00:06:01,620 --> 00:06:04,800 and we can see it's becoming effective immediately 123 00:06:04,800 --> 00:06:07,140 because my color is set to blue. 124 00:06:07,140 --> 00:06:09,450 And that is how you can use these different 125 00:06:09,450 --> 00:06:10,743 Bash startup files.