WEBVTT

1
00:00:00.120 --> 00:00:03.359
<v Speaker 1>Imagine finding a hidden door in your house that you

2
00:00:03.399 --> 00:00:04.759
<v Speaker 1>never knew existed.

3
00:00:04.799 --> 00:00:06.799
<v Speaker 2>Like a secret passage or something exactly.

4
00:00:06.879 --> 00:00:09.199
<v Speaker 1>Yeah, you pry it open, you step inside, and you

5
00:00:09.240 --> 00:00:11.439
<v Speaker 1>realize it's an entire master control room.

6
00:00:11.679 --> 00:00:11.960
<v Speaker 2>Wow.

7
00:00:12.320 --> 00:00:15.359
<v Speaker 1>Right, and suddenly you can bypass every single like switch,

8
00:00:15.400 --> 00:00:18.239
<v Speaker 1>every thermostat, every lock in the building. You just have

9
00:00:18.359 --> 00:00:23.359
<v Speaker 1>this absolute, unfettered access to the underlying wiring of your home.

10
00:00:23.679 --> 00:00:25.960
<v Speaker 2>That's a powerful image and a little.

11
00:00:25.679 --> 00:00:28.800
<v Speaker 1>Intimidating it is, But I mean that is exactly what

12
00:00:28.839 --> 00:00:30.920
<v Speaker 1>happens when you open the command line on your computer.

13
00:00:31.679 --> 00:00:36.399
<v Speaker 1>So welcome to this custom tailored deep dive, designed specifically

14
00:00:36.399 --> 00:00:36.799
<v Speaker 1>for you.

15
00:00:36.960 --> 00:00:38.159
<v Speaker 2>Glad to be here for this one.

16
00:00:38.280 --> 00:00:42.200
<v Speaker 1>Yeah, Our mission today is to demystify this hidden world,

17
00:00:42.560 --> 00:00:46.039
<v Speaker 1>and we're using excerpts from the Bashed cookbook. So, whether

18
00:00:46.079 --> 00:00:49.719
<v Speaker 1>you're a seasoned programmer or you know, just insanely curious

19
00:00:49.759 --> 00:00:52.520
<v Speaker 1>about what happens behind that graphical curtain of your desktop,

20
00:00:52.960 --> 00:00:56.399
<v Speaker 1>our goal is to reveal how mastering this text based

21
00:00:56.520 --> 00:00:59.960
<v Speaker 1>layer is. Well, it's basically a shortcut to total control

22
00:01:00.079 --> 00:01:00.799
<v Speaker 1>over your machine.

23
00:01:00.880 --> 00:01:04.000
<v Speaker 2>Yeah, Because you know, most of us are just entirely

24
00:01:04.040 --> 00:01:08.200
<v Speaker 2>accustomed to a visual, white and click reality. We navigate

25
00:01:08.200 --> 00:01:10.840
<v Speaker 2>our digital lives the exact same way we navigate a

26
00:01:10.840 --> 00:01:13.439
<v Speaker 2>physical kitchen. Like, if you want to throw a file away,

27
00:01:14.200 --> 00:01:15.840
<v Speaker 2>you look for a little trash can icon.

28
00:01:15.760 --> 00:01:18.439
<v Speaker 1>Right to grab the file, drag it over done exactly.

29
00:01:18.519 --> 00:01:22.319
<v Speaker 2>It's spatial and it feels safe. But when you strip

30
00:01:22.319 --> 00:01:27.280
<v Speaker 2>away that graphical illusion, the trash can just vanishes, goof gone, right,

31
00:01:27.319 --> 00:01:30.439
<v Speaker 2>and you're left staring at a blank screen with just

32
00:01:30.560 --> 00:01:34.599
<v Speaker 2>a blinking cursor. I mean, it is an incredibly powerful

33
00:01:34.680 --> 00:01:37.519
<v Speaker 2>text based environment, but it's just sitting there waiting for

34
00:01:37.599 --> 00:01:38.560
<v Speaker 2>direct instructions.

35
00:01:38.680 --> 00:01:41.680
<v Speaker 1>Okay, let's unpack this because before we can start typing

36
00:01:41.719 --> 00:01:44.200
<v Speaker 1>commands into that blank screen, we kind of need to

37
00:01:44.280 --> 00:01:47.519
<v Speaker 1>understand what we're actually typing into. We use the word

38
00:01:47.599 --> 00:01:50.719
<v Speaker 1>shell all the time and computing, but to really grasp

39
00:01:50.840 --> 00:01:54.920
<v Speaker 1>why a shell even exists, we have to rewind all

40
00:01:54.959 --> 00:01:57.200
<v Speaker 1>the way to the nineteen seventies and look at the

41
00:01:57.239 --> 00:01:59.200
<v Speaker 1>creation of the Unix operating system.

42
00:01:59.400 --> 00:02:01.519
<v Speaker 2>Yeah, and if we connect this to the bigger picture,

43
00:02:01.760 --> 00:02:04.599
<v Speaker 2>early computing was highly highly monolithic.

44
00:02:04.719 --> 00:02:05.959
<v Speaker 1>What do you mean by monolithic?

45
00:02:06.079 --> 00:02:08.520
<v Speaker 2>Well, the user interface and the core operating system were

46
00:02:08.560 --> 00:02:11.599
<v Speaker 2>just welded together in one massive piece of software. Oh

47
00:02:11.599 --> 00:02:14.759
<v Speaker 2>I see, Yeah, you were completely stuck with whatever interface

48
00:02:14.800 --> 00:02:19.159
<v Speaker 2>the hardware vendor decided to provide. But the brilliant concept

49
00:02:19.280 --> 00:02:24.599
<v Speaker 2>behind Unix was this clean, deliberate separation. They split the

50
00:02:24.639 --> 00:02:28.120
<v Speaker 2>system into two distinct parts, the kernel and the shell.

51
00:02:28.400 --> 00:02:31.280
<v Speaker 2>Kernel in the shell, right, the kernel is the core.

52
00:02:31.439 --> 00:02:34.560
<v Speaker 2>It handles all the brutal heavy lifting of computing, like

53
00:02:35.039 --> 00:02:39.319
<v Speaker 2>managing memory allocations, talking directly to the physical hardware, scheduling

54
00:02:39.360 --> 00:02:42.319
<v Speaker 2>CPU time, and nuts and bolts. Exactly. It's all the

55
00:02:42.319 --> 00:02:45.479
<v Speaker 2>stuff the average user never ever wants to manage manually.

56
00:02:45.639 --> 00:02:49.560
<v Speaker 1>So if the kernel is essentially the car's engine and

57
00:02:49.599 --> 00:02:50.240
<v Speaker 1>the drive.

58
00:02:50.080 --> 00:02:51.639
<v Speaker 2>Train, right, that's a good way to look at it.

59
00:02:51.680 --> 00:02:54.280
<v Speaker 1>Then the shell, I guess, is the steering wheel, the pedals,

60
00:02:54.319 --> 00:02:56.919
<v Speaker 1>and the dashboard. It's the interface that lets the driver

61
00:02:57.039 --> 00:02:58.439
<v Speaker 1>actually tell the engine what to do.

62
00:02:58.719 --> 00:03:03.439
<v Speaker 2>Yes, the absolute genius of UNUS was realizing that you

63
00:03:03.479 --> 00:03:06.439
<v Speaker 2>could swap out the steering wheel without having to rebuild

64
00:03:06.479 --> 00:03:09.960
<v Speaker 2>the entire engine from scratch, which is huge. It is revolutionary.

65
00:03:10.120 --> 00:03:12.759
<v Speaker 2>The shell became just another swappable program.

66
00:03:12.400 --> 00:03:15.479
<v Speaker 1>And that decoupling must have allowed for like an absolute

67
00:03:15.520 --> 00:03:16.879
<v Speaker 1>explosion of innovation right.

68
00:03:17.199 --> 00:03:21.639
<v Speaker 2>Oh, completely, because if developers felt a command interface was inefficient,

69
00:03:22.000 --> 00:03:24.599
<v Speaker 2>they didn't have to go and convince a massive corporation

70
00:03:24.960 --> 00:03:27.000
<v Speaker 2>to update an entire operating system.

71
00:03:27.039 --> 00:03:29.199
<v Speaker 1>They could just build their own steering wheel exactly.

72
00:03:29.240 --> 00:03:31.479
<v Speaker 2>They can simply write a new shell, and they did.

73
00:03:31.800 --> 00:03:34.560
<v Speaker 2>I mean, the sources mentioned the original born shell, which

74
00:03:34.599 --> 00:03:38.680
<v Speaker 2>was known as SHE. Then the CShell Shish emerged. It

75
00:03:38.759 --> 00:03:41.879
<v Speaker 2>had some new user conveniences, but it had quirks that

76
00:03:41.919 --> 00:03:43.400
<v Speaker 2>made programming kind of difficult.

77
00:03:43.479 --> 00:03:44.680
<v Speaker 1>Gotcha.

78
00:03:44.840 --> 00:03:49.439
<v Speaker 2>Following that was the corn Shell Gish, And finally, the

79
00:03:49.560 --> 00:03:53.520
<v Speaker 2>undisputed star of our source material today, the Born Again

80
00:03:53.639 --> 00:03:55.919
<v Speaker 2>Shell or Bash bash.

81
00:03:55.680 --> 00:03:58.400
<v Speaker 1>Which is basically everywhere now. Like, if you open a

82
00:03:58.520 --> 00:04:02.080
<v Speaker 1>terminal on almost any line Nicks distribution or a Mac today,

83
00:04:02.599 --> 00:04:04.000
<v Speaker 1>you were likely looking at Bash.

84
00:04:04.199 --> 00:04:05.120
<v Speaker 2>Oh almost certainly.

85
00:04:05.159 --> 00:04:07.879
<v Speaker 1>And the sources point out it achieved this total dominance

86
00:04:08.000 --> 00:04:11.159
<v Speaker 1>largely due to the open source movement, right specifically the

87
00:04:11.199 --> 00:04:14.000
<v Speaker 1>Genu project. Like Brian Fox wrote Bash as a free

88
00:04:14.039 --> 00:04:15.879
<v Speaker 1>replacement for the original born Shell.

89
00:04:15.960 --> 00:04:17.199
<v Speaker 2>Yeah, that was a huge part of it.

90
00:04:17.439 --> 00:04:21.199
<v Speaker 1>But there's also this term mentioned in the text POSEX standardization.

91
00:04:21.759 --> 00:04:24.439
<v Speaker 1>What actually is PO six and why did it help

92
00:04:24.600 --> 00:04:26.079
<v Speaker 1>Bash take over the world?

93
00:04:26.279 --> 00:04:30.360
<v Speaker 2>Right? So PO six stands for Portable Operating System interface. Okay,

94
00:04:30.800 --> 00:04:34.800
<v Speaker 2>back in the day, different versions of Unix were fragmenting badly,

95
00:04:35.360 --> 00:04:38.920
<v Speaker 2>like a script written on one system might completely break

96
00:04:38.920 --> 00:04:42.439
<v Speaker 2>on another because the underlying commands behaved just slightly differently.

97
00:04:42.519 --> 00:04:44.639
<v Speaker 1>Oh, that sounds like a nightmare for developers.

98
00:04:44.759 --> 00:04:48.199
<v Speaker 2>It was so. POSX was created as a standardized set

99
00:04:48.240 --> 00:04:51.439
<v Speaker 2>of rules. It dictated exactly how an operating system and

100
00:04:51.480 --> 00:04:54.639
<v Speaker 2>its shell should behave and Bash was designed to be

101
00:04:54.959 --> 00:04:56.560
<v Speaker 2>highly POSEX compliant.

102
00:04:56.879 --> 00:04:59.279
<v Speaker 1>Ah, so it was like a guarantee exactly.

103
00:04:59.519 --> 00:05:01.560
<v Speaker 2>It meant to developers knew if they wrote a script

104
00:05:01.560 --> 00:05:05.600
<v Speaker 2>for Bash, it would run reliably across wildly different hardware systems.

105
00:05:05.920 --> 00:05:09.319
<v Speaker 2>It essentially became the universal translator of systems administration.

106
00:05:09.519 --> 00:05:11.720
<v Speaker 1>That makes total sense. So, okay, now that we know

107
00:05:11.759 --> 00:05:14.800
<v Speaker 1>we're sitting behind the swappable steering wheel called Bash, we

108
00:05:14.920 --> 00:05:15.879
<v Speaker 1>need to know how to.

109
00:05:15.879 --> 00:05:17.959
<v Speaker 2>Read the dashboard, right, the interface itself.

110
00:05:18.199 --> 00:05:22.199
<v Speaker 1>Yeah, we're staring at that blinking cursor and it's sitting

111
00:05:22.319 --> 00:05:25.079
<v Speaker 1>right next to something called the prompt. And according to

112
00:05:25.120 --> 00:05:28.680
<v Speaker 1>the cookbook, that prompt is packed with vital information about

113
00:05:28.720 --> 00:05:30.480
<v Speaker 1>who you are and what you can do.

114
00:05:30.639 --> 00:05:32.199
<v Speaker 2>It tells you everything you need to know about your

115
00:05:32.279 --> 00:05:32.759
<v Speaker 2>current state.

116
00:05:32.920 --> 00:05:36.160
<v Speaker 1>Right, and the very last character of the prompt is

117
00:05:36.439 --> 00:05:39.800
<v Speaker 1>the dead giveaway like a trailing dollar sign means you

118
00:05:39.839 --> 00:05:44.040
<v Speaker 1>are logged in as a regular user with standard safe permissions. Yes,

119
00:05:44.240 --> 00:05:47.720
<v Speaker 1>but if you see a hash sign, you know the pound.

120
00:05:47.399 --> 00:05:49.560
<v Speaker 2>Symbol ake, you need to be very very careful.

121
00:05:49.600 --> 00:05:51.040
<v Speaker 1>Why what does the hash mean?

122
00:05:51.360 --> 00:05:53.759
<v Speaker 2>It means you are operating as root, that is the

123
00:05:53.920 --> 00:05:58.920
<v Speaker 2>all powerful system administrator account. You have zero restrictions. You

124
00:05:58.920 --> 00:06:03.000
<v Speaker 2>can modify any file, read any data, and consequently you

125
00:06:03.040 --> 00:06:06.600
<v Speaker 2>can accidentally obliterate the entire operating system with a single typo.

126
00:06:07.000 --> 00:06:09.959
<v Speaker 1>Yikes. So the ash symbol is basically a glaring red

127
00:06:09.959 --> 00:06:12.720
<v Speaker 1>warning light that the safety rails are completely off.

128
00:06:12.800 --> 00:06:15.519
<v Speaker 2>Precisely, it's the shell saying I will do whatever you type,

129
00:06:15.600 --> 00:06:17.120
<v Speaker 2>even if it destroys everything.

130
00:06:17.360 --> 00:06:20.600
<v Speaker 1>Good to know. Okay, So, assuming we are safely using

131
00:06:20.600 --> 00:06:22.879
<v Speaker 1>our dollar sign prompt, we actually want to run a command.

132
00:06:22.879 --> 00:06:25.560
<v Speaker 1>The cookbook details several ways to find the tools we need.

133
00:06:25.720 --> 00:06:27.680
<v Speaker 2>Right, Finding the right command is half the battle.

134
00:06:27.839 --> 00:06:31.079
<v Speaker 1>Yeah. So there's type, which tells you if a command

135
00:06:31.240 --> 00:06:33.879
<v Speaker 1>is a built in shell function or an external file.

136
00:06:34.319 --> 00:06:38.199
<v Speaker 1>There's which which locates the exact folder a command lives in.

137
00:06:39.120 --> 00:06:41.439
<v Speaker 1>And there's appropos, which I think is brilliant if you

138
00:06:41.439 --> 00:06:43.120
<v Speaker 1>can't remember a command's name, you just give it a

139
00:06:43.199 --> 00:06:47.879
<v Speaker 1>keyword and it searches the system's manual pages using regular expressions.

140
00:06:47.279 --> 00:06:48.759
<v Speaker 2>Which is incredibly helpful.

141
00:06:48.920 --> 00:06:52.680
<v Speaker 1>Yeah, and for anyone unfamiliar, a regular expression is essentially

142
00:06:52.720 --> 00:06:55.600
<v Speaker 1>a sequence of characters that acts like a highly advanced,

143
00:06:55.720 --> 00:06:59.959
<v Speaker 1>super powered search pattern. But this brings up a mechanical

144
00:07:00.240 --> 00:07:03.360
<v Speaker 1>question for me. Okay, shoot, when I type something simple

145
00:07:03.759 --> 00:07:06.839
<v Speaker 1>like l's to list my files, how does the shell

146
00:07:06.879 --> 00:07:09.560
<v Speaker 1>actually know where that specific program is located on my

147
00:07:09.600 --> 00:07:10.120
<v Speaker 1>hard drive?

148
00:07:10.279 --> 00:07:14.480
<v Speaker 2>Oh? Well, it relies on an environment variable called the path.

149
00:07:14.639 --> 00:07:17.639
<v Speaker 2>The path Yeah, the path through is simply a text

150
00:07:17.720 --> 00:07:21.480
<v Speaker 2>string containing a list of direct relocations, and they're separated

151
00:07:21.519 --> 00:07:25.360
<v Speaker 2>by colon's. Think of it as the shell's authorized search map.

152
00:07:25.560 --> 00:07:26.639
<v Speaker 1>Okay, a search map.

153
00:07:26.800 --> 00:07:29.959
<v Speaker 2>Right. When you type l's and a hit ender, Bash

154
00:07:30.000 --> 00:07:32.959
<v Speaker 2>doesn't just scan your entire hard drive. That would take

155
00:07:33.120 --> 00:07:33.920
<v Speaker 2>entirely too long.

156
00:07:34.040 --> 00:07:35.800
<v Speaker 1>Oh yeah, that would be agonizing.

157
00:07:36.199 --> 00:07:39.680
<v Speaker 2>Instead, it reads the path variable and checks the first

158
00:07:39.759 --> 00:07:43.000
<v Speaker 2>folder on that list. If it finds an executable file

159
00:07:43.079 --> 00:07:45.800
<v Speaker 2>named l's in that folder, it runs it immediately and

160
00:07:45.879 --> 00:07:48.839
<v Speaker 2>stops searching. If not, it moves to the second folder,

161
00:07:49.079 --> 00:07:50.199
<v Speaker 2>then the third, and so on.

162
00:07:50.399 --> 00:07:52.519
<v Speaker 1>Wait, wait, I have to stop you there, because wouldn't

163
00:07:52.519 --> 00:07:55.240
<v Speaker 1>it be infinitely easier to have the computer check the

164
00:07:55.240 --> 00:07:57.040
<v Speaker 1>folder I'm currently standing in first?

165
00:07:57.040 --> 00:07:57.920
<v Speaker 2>You would think, so, right?

166
00:07:58.000 --> 00:08:00.519
<v Speaker 1>I mean, if I'm working inside a specific project folder

167
00:08:00.519 --> 00:08:03.480
<v Speaker 1>and I type a command, logic dictates the shell should

168
00:08:03.480 --> 00:08:05.120
<v Speaker 1>look right in front of my face before it goes

169
00:08:05.160 --> 00:08:08.000
<v Speaker 1>trekking across the entire system map. Why on earth is

170
00:08:08.040 --> 00:08:08.879
<v Speaker 1>it designed this way?

171
00:08:08.959 --> 00:08:12.199
<v Speaker 2>Well, this raises an important question about the tension between

172
00:08:12.240 --> 00:08:15.480
<v Speaker 2>convenience and security. Let's walk through what happens if we

173
00:08:15.519 --> 00:08:18.439
<v Speaker 2>can figure your path the exact way you just described.

174
00:08:19.480 --> 00:08:22.399
<v Speaker 2>We put your current directory, which Unix represents with a

175
00:08:22.439 --> 00:08:24.600
<v Speaker 2>single dot. By the way, at the very front of

176
00:08:24.639 --> 00:08:26.639
<v Speaker 2>your path makes sense to me. So the shell will

177
00:08:26.639 --> 00:08:28.560
<v Speaker 2>now check whatever fold do you happen to be in

178
00:08:28.879 --> 00:08:30.680
<v Speaker 2>before it checks the official system.

179
00:08:30.399 --> 00:08:33.480
<v Speaker 1>Folders, which sounds incredibly efficient.

180
00:08:33.240 --> 00:08:35.519
<v Speaker 2>Until you wander into a directory created by someone with

181
00:08:35.559 --> 00:08:40.240
<v Speaker 2>malicious intent. Oh no, yeah, a bad actor knows that

182
00:08:40.320 --> 00:08:44.600
<v Speaker 2>systems administrators frequently take LS to see what is inside

183
00:08:44.639 --> 00:08:46.279
<v Speaker 2>a newly downloaded folder.

184
00:08:46.840 --> 00:08:50.200
<v Speaker 1>It's muscle memory, right, you enter a folder, you type LS.

185
00:08:50.000 --> 00:08:55.240
<v Speaker 2>Exactly, So this bad actor writes a highly destructive script,

186
00:08:55.480 --> 00:08:59.679
<v Speaker 2>Maybe something that silently deletes databases or steals passwords. And

187
00:08:59.720 --> 00:09:02.080
<v Speaker 2>they say that script in their folder and they name

188
00:09:02.120 --> 00:09:02.639
<v Speaker 2>it els.

189
00:09:02.960 --> 00:09:04.240
<v Speaker 1>Oh, I see where this is going.

190
00:09:04.320 --> 00:09:07.279
<v Speaker 2>You navigate into their trap folder. You type ls fully

191
00:09:07.279 --> 00:09:09.879
<v Speaker 2>expecting to see a list of files, But because your

192
00:09:09.879 --> 00:09:12.720
<v Speaker 2>path is configured to check your current directory first, the

193
00:09:12.799 --> 00:09:16.480
<v Speaker 2>shell finds their malicious script named l's and executes it

194
00:09:16.799 --> 00:09:20.360
<v Speaker 2>using your account privileges. That is terrifying, and the shell

195
00:09:20.639 --> 00:09:25.639
<v Speaker 2>stops searching instantly. It never even reaches the real secure

196
00:09:25.639 --> 00:09:29.360
<v Speaker 2>Indel's program that's located deep in the system's binary folders.

197
00:09:29.399 --> 00:09:29.720
<v Speaker 1>Wow.

198
00:09:30.120 --> 00:09:34.159
<v Speaker 2>Yeah. By forcing the path to search the official lockdown

199
00:09:34.240 --> 00:09:37.879
<v Speaker 2>system directories first, the architecture guarantees you are running the

200
00:09:38.000 --> 00:09:41.399
<v Speaker 2>genuine tools, regardless of what traps someone left in your

201
00:09:41.399 --> 00:09:42.279
<v Speaker 2>current working folder.

202
00:09:42.440 --> 00:09:46.320
<v Speaker 1>That is beautifully devious and a phenomenal reason to never

203
00:09:46.480 --> 00:09:48.840
<v Speaker 1>ever put the dot directory at the front of your path.

204
00:09:49.000 --> 00:09:50.159
<v Speaker 2>Exactly never do it.

205
00:09:50.519 --> 00:09:53.519
<v Speaker 1>So Okay, we know how the shell safely locates and

206
00:09:53.559 --> 00:09:57.039
<v Speaker 1>triggers commands, but triggering a command is only half the battle.

207
00:09:57.639 --> 00:10:00.000
<v Speaker 1>We need to deal with the data those commands.

208
00:09:59.679 --> 00:10:01.159
<v Speaker 2>Produce, right, the actual output.

209
00:10:01.320 --> 00:10:03.799
<v Speaker 1>Yeah, and this introduces us to what is arguably the

210
00:10:03.799 --> 00:10:06.360
<v Speaker 1>most famous core philosophy of Unix.

211
00:10:06.559 --> 00:10:09.200
<v Speaker 2>Everything is a file, yes, the Golden rule.

212
00:10:09.399 --> 00:10:12.639
<v Speaker 1>The cookbook emphasizes that. To the operating system, a hard

213
00:10:12.720 --> 00:10:15.440
<v Speaker 1>drive is a file, a terminal window is a file,

214
00:10:15.480 --> 00:10:18.000
<v Speaker 1>and your keyboard is a file. The system treats all

215
00:10:18.039 --> 00:10:20.440
<v Speaker 1>of them as just an ordered sequence of bytes. But

216
00:10:20.480 --> 00:10:22.840
<v Speaker 1>I have to push back on that though. Calling everything

217
00:10:22.879 --> 00:10:27.440
<v Speaker 1>a file sounds incredibly reductive. Like a keyboard has physical

218
00:10:27.519 --> 00:10:32.279
<v Speaker 1>mechanical switches, a hard drive has spinning magnetic platters. Treating

219
00:10:32.320 --> 00:10:34.759
<v Speaker 1>them is the exact same thing. Seems like you're stripping

220
00:10:34.759 --> 00:10:37.200
<v Speaker 1>away all the functionality that makes them useful.

221
00:10:37.559 --> 00:10:41.000
<v Speaker 2>Well, what's fascinating here is that the stripping away is

222
00:10:41.039 --> 00:10:45.440
<v Speaker 2>the entire point. Really, Yeah, that radical simplification is exactly

223
00:10:45.480 --> 00:10:48.559
<v Speaker 2>what gives the command line its power. Yes, the physical

224
00:10:48.559 --> 00:10:52.200
<v Speaker 2>hardware is vastly different, but remember are split between the

225
00:10:52.279 --> 00:10:54.399
<v Speaker 2>kernel and the shell earlier, right.

226
00:10:54.279 --> 00:10:55.600
<v Speaker 1>The engine and the steering wheel.

227
00:10:55.679 --> 00:10:59.039
<v Speaker 2>Exactly. Yeah, the kernel handles the magnetic platters and the

228
00:10:59.080 --> 00:11:03.320
<v Speaker 2>mechanical switches. It translates those physical actions into a simple

229
00:11:03.360 --> 00:11:06.120
<v Speaker 2>stream of digital bytes. So by the time that data

230
00:11:06.159 --> 00:11:09.279
<v Speaker 2>reaches the shell, all that hardware complexity is just gone.

231
00:11:09.559 --> 00:11:11.960
<v Speaker 2>Oh I get it, because the shell treats everything as

232
00:11:12.000 --> 00:11:15.159
<v Speaker 2>a simple file stream. A software developer doesn't need to

233
00:11:15.159 --> 00:11:17.960
<v Speaker 2>know how to program a driver for a specific brand

234
00:11:18.000 --> 00:11:20.759
<v Speaker 2>of keyboard or a specific model of monitor.

235
00:11:21.000 --> 00:11:23.240
<v Speaker 1>They just write a program that reads bytes from an

236
00:11:23.279 --> 00:11:25.879
<v Speaker 1>input file and writes bites to an output file.

237
00:11:26.200 --> 00:11:32.000
<v Speaker 2>Precisely, the shell seamlessly connects those files to the physical hardware.

238
00:11:31.639 --> 00:11:34.279
<v Speaker 1>Which means before we start passing these bytes streams around,

239
00:11:34.279 --> 00:11:35.840
<v Speaker 1>we really have to talk about quoting.

240
00:11:35.960 --> 00:11:36.159
<v Speaker 2>Oh.

241
00:11:36.279 --> 00:11:39.519
<v Speaker 1>Quoting is crucial because if you just type raw text

242
00:11:39.559 --> 00:11:41.879
<v Speaker 1>into the shell, it will try to interpret it. The

243
00:11:41.919 --> 00:11:45.440
<v Speaker 1>cookbook uses this fantastic example trying to get the shell

244
00:11:45.480 --> 00:11:49.360
<v Speaker 1>to print the sentence a coffee is five dollars.

245
00:11:49.360 --> 00:11:51.679
<v Speaker 2>Right with the dollar sign and the exclamation point.

246
00:11:51.799 --> 00:11:55.600
<v Speaker 1>Yeah, if you wrap that sentence in double quotes, the

247
00:11:55.600 --> 00:11:58.559
<v Speaker 1>shell tries to be entirely too helpful. It sees the

248
00:11:58.559 --> 00:12:01.639
<v Speaker 1>dollar sign and thinks, aha, that is a variable. I

249
00:12:01.679 --> 00:12:04.360
<v Speaker 1>need to swap five dollars out for whatever value is

250
00:12:04.399 --> 00:12:05.120
<v Speaker 1>stored in memory.

251
00:12:05.159 --> 00:12:07.000
<v Speaker 2>But there is no variable named five.

252
00:12:06.919 --> 00:12:10.200
<v Speaker 1>Exactly, so it replaces five dollars with absolutely nothing. Then

253
00:12:10.240 --> 00:12:13.679
<v Speaker 1>it scans further sees the exclamation point. Assumes you want

254
00:12:13.679 --> 00:12:16.480
<v Speaker 1>to run a history substitution to pull up a previous command,

255
00:12:16.639 --> 00:12:18.759
<v Speaker 1>and the whole thing just throws an error.

256
00:12:18.799 --> 00:12:22.440
<v Speaker 2>It's chaos. The shell basically acts like an overeager assistant

257
00:12:22.440 --> 00:12:24.960
<v Speaker 2>trying to interpret your words before passing them to the

258
00:12:25.000 --> 00:12:25.919
<v Speaker 2>actual program.

259
00:12:26.000 --> 00:12:27.600
<v Speaker 1>An over eager assistant.

260
00:12:27.639 --> 00:12:29.559
<v Speaker 2>That's perfect, yees. So if you want the assistant to

261
00:12:29.600 --> 00:12:32.159
<v Speaker 2>back off and take you literally, you use single quotes.

262
00:12:32.399 --> 00:12:33.159
<v Speaker 1>Single quotes.

263
00:12:33.480 --> 00:12:37.919
<v Speaker 2>Single quotes form an impenetrable barrier. They completely disable the

264
00:12:37.960 --> 00:12:41.480
<v Speaker 2>shell's ability to interpret special characters, so the dollar sign

265
00:12:41.519 --> 00:12:44.440
<v Speaker 2>and the exclamation point are treated merely as shapes on

266
00:12:44.480 --> 00:12:48.120
<v Speaker 2>the screen. What you type inside single quotes is exactly

267
00:12:48.159 --> 00:12:49.120
<v Speaker 2>what gets passed along.

268
00:12:49.279 --> 00:12:52.519
<v Speaker 1>Okay, so here's where it gets really interesting. Once your

269
00:12:52.559 --> 00:12:55.559
<v Speaker 1>text is protected and your commands are running, you can

270
00:12:55.559 --> 00:12:56.759
<v Speaker 1>start building the plumbing.

271
00:12:56.879 --> 00:12:57.399
<v Speaker 2>The plumbing.

272
00:12:57.480 --> 00:12:59.960
<v Speaker 1>Yes, we use the greater than sign to read diirect

273
00:13:00.200 --> 00:13:03.360
<v Speaker 1>output into a text file, a double grater than to

274
00:13:03.720 --> 00:13:06.200
<v Speaker 1>append to the bottom of an existing file, and the

275
00:13:06.279 --> 00:13:09.159
<v Speaker 1>less than sign to pull input into a program from a.

276
00:13:09.080 --> 00:13:10.519
<v Speaker 2>File standard redirection.

277
00:13:10.759 --> 00:13:13.960
<v Speaker 1>Right, But the show is actually performing some incredibly clever

278
00:13:14.080 --> 00:13:15.360
<v Speaker 1>deception behind the scenes.

279
00:13:15.360 --> 00:13:15.559
<v Speaker 2>Here.

280
00:13:16.039 --> 00:13:19.759
<v Speaker 1>The cookbook highlights this bizarre anomaly with the l's command

281
00:13:19.840 --> 00:13:21.480
<v Speaker 1>that completely caught me off guard.

282
00:13:21.639 --> 00:13:22.840
<v Speaker 2>Oh, the column formatting.

283
00:13:22.960 --> 00:13:25.679
<v Speaker 1>Yes, if you type l's rows directly into your terminal,

284
00:13:25.879 --> 00:13:28.559
<v Speaker 1>it formats your files into neat wide columns so they

285
00:13:28.559 --> 00:13:31.399
<v Speaker 1>fit perfectly on your monitor. But if you type l's

286
00:13:31.440 --> 00:13:34.399
<v Speaker 1>and use the greater then sign to redirect that exact

287
00:13:34.480 --> 00:13:37.679
<v Speaker 1>same output into a text file, the formatting changes.

288
00:13:37.799 --> 00:13:38.159
<v Speaker 2>It does.

289
00:13:38.320 --> 00:13:40.759
<v Speaker 1>You open the file and the columns are just gone.

290
00:13:41.200 --> 00:13:44.840
<v Speaker 1>It's a single, massive, vertical list, one file per line.

291
00:13:45.799 --> 00:13:48.399
<v Speaker 1>How does the program know we redirected it? I mean,

292
00:13:48.399 --> 00:13:50.840
<v Speaker 1>how does it No, it's not looking at a screen anymore.

293
00:13:51.000 --> 00:13:53.279
<v Speaker 2>So to understand the mechanism behind that, we have to

294
00:13:53.320 --> 00:13:54.600
<v Speaker 2>talk about file descriptors.

295
00:13:54.639 --> 00:13:55.679
<v Speaker 1>Okay, file descriptor.

296
00:13:55.759 --> 00:13:58.879
<v Speaker 2>A file descriptor is basically just an ID tag, a

297
00:13:58.960 --> 00:14:02.759
<v Speaker 2>simple number the operating system assigns to an open data stream,

298
00:14:03.120 --> 00:14:06.639
<v Speaker 2>and by default, every single program gets three of these

299
00:14:06.679 --> 00:14:09.759
<v Speaker 2>ID tags the moment it starts. Just three, just three.

300
00:14:10.000 --> 00:14:13.120
<v Speaker 2>File descriptor zero is standard input, which is usually your keyboard,

301
00:14:13.279 --> 00:14:16.360
<v Speaker 2>file scripture one is standard output, usually your screen, and

302
00:14:16.480 --> 00:14:19.360
<v Speaker 2>file descriptor two is standard air, also usually your screen.

303
00:14:19.679 --> 00:14:22.000
<v Speaker 1>Okay, so zero, one and two, right, So.

304
00:14:21.960 --> 00:14:24.600
<v Speaker 2>When you use the greater than sign, you are telling

305
00:14:24.639 --> 00:14:27.759
<v Speaker 2>the shell take file descriptor one, disconnect it from the

306
00:14:27.759 --> 00:14:29.919
<v Speaker 2>monitor and plug it into this text file instead.

307
00:14:30.399 --> 00:14:32.960
<v Speaker 1>Wait, the redirection is supposed to be invisible to the program,

308
00:14:33.039 --> 00:14:35.919
<v Speaker 1>right the program just keeps pushing bytes to descriptor one.

309
00:14:36.240 --> 00:14:39.600
<v Speaker 2>Generally, yes, that's the beauty of it. But programs are

310
00:14:39.639 --> 00:14:42.799
<v Speaker 2>actually allowed to ask the operating system, hey, what exactly

311
00:14:42.840 --> 00:14:45.360
<v Speaker 2>is my file descriptor one plugged into? Right now? O?

312
00:14:45.799 --> 00:14:46.039
<v Speaker 1>Way?

313
00:14:46.440 --> 00:14:50.039
<v Speaker 2>Yeah, The developers of L's added a tiny check. The

314
00:14:50.080 --> 00:14:53.279
<v Speaker 2>program queries the OS. If the OS replies, you are

315
00:14:53.279 --> 00:14:57.039
<v Speaker 2>plugged into a terminal display, then LS calculates the width

316
00:14:57.080 --> 00:15:00.679
<v Speaker 2>of the screen and neatly arranges the columns for human eyes.

317
00:15:00.840 --> 00:15:02.879
<v Speaker 1>But if it's plugged into a file exactly.

318
00:15:03.000 --> 00:15:05.159
<v Speaker 2>If the ALWAYS replies you are plugged into a flat

319
00:15:05.200 --> 00:15:08.759
<v Speaker 2>text file, L's knows the human isn't reading it right now.

320
00:15:08.840 --> 00:15:11.159
<v Speaker 2>It knows another program is likely going to parse that

321
00:15:11.200 --> 00:15:15.360
<v Speaker 2>file later, and parsing a single predictable vertical list is

322
00:15:15.559 --> 00:15:19.159
<v Speaker 2>drastically easier for a computer than trying to untangle columns.

323
00:15:19.440 --> 00:15:22.360
<v Speaker 1>Is that underlying logic is brilliant. It literally adapts to

324
00:15:22.399 --> 00:15:23.679
<v Speaker 1>the medium it's being sent to.

325
00:15:23.840 --> 00:15:24.720
<v Speaker 2>It's very smart.

326
00:15:24.960 --> 00:15:27.039
<v Speaker 1>And speaking of plumbing, that brings us back to those

327
00:15:27.080 --> 00:15:30.600
<v Speaker 1>file descriptors you mentioned specifically standard output which is one,

328
00:15:30.720 --> 00:15:34.720
<v Speaker 1>and standard error which is two. This perfectly explains a headache.

329
00:15:34.720 --> 00:15:36.000
<v Speaker 1>I think literally everyone.

330
00:15:35.759 --> 00:15:37.080
<v Speaker 2>Encounters all the error bleed.

331
00:15:37.279 --> 00:15:40.879
<v Speaker 1>Yes, you run a command that generates a massive wall

332
00:15:40.960 --> 00:15:44.120
<v Speaker 1>of text, including a bunch of error messages. You decide

333
00:15:44.120 --> 00:15:46.639
<v Speaker 1>to save it, so you use the greater than sign

334
00:15:46.879 --> 00:15:49.960
<v Speaker 1>to redirect the output to a file. Right, you hit enter,

335
00:15:50.440 --> 00:15:52.919
<v Speaker 1>and all the normal text goes quietly into the file,

336
00:15:52.960 --> 00:15:55.759
<v Speaker 1>but the error message is still bleed all over your screen.

337
00:15:55.799 --> 00:15:57.559
<v Speaker 1>It's so frustrating, it.

338
00:15:57.480 --> 00:16:00.840
<v Speaker 2>Is, But that happens because the sta entered greater than

339
00:16:00.919 --> 00:16:05.840
<v Speaker 2>sign only redirects file descriptor one. Oh yes, Stream one

340
00:16:05.919 --> 00:16:08.919
<v Speaker 2>goes to the file, but stream two, the errors remains

341
00:16:08.960 --> 00:16:12.039
<v Speaker 2>plugged directly into your monitor. To catch the errors, you

342
00:16:12.080 --> 00:16:15.360
<v Speaker 2>have to explicitly redirect descriptor two by typing too.

343
00:16:15.639 --> 00:16:16.440
<v Speaker 1>Ah okay.

344
00:16:16.519 --> 00:16:20.000
<v Speaker 2>But the cookbook also highlights a vital, highly technical nuance

345
00:16:20.039 --> 00:16:24.759
<v Speaker 2>regarding how these two streams deliver their payloads. And that's buffering, right, buffering.

346
00:16:24.840 --> 00:16:27.879
<v Speaker 1>So standard output is buffered, meaning it acts like a bucket.

347
00:16:28.000 --> 00:16:30.360
<v Speaker 1>The program doesn't send data to the screen one letter

348
00:16:30.399 --> 00:16:32.240
<v Speaker 1>at a time. It fills up a memory bucket, and

349
00:16:32.279 --> 00:16:35.200
<v Speaker 1>when the bucket is full, it dumps the whole chunk

350
00:16:35.240 --> 00:16:36.279
<v Speaker 1>to the scream at once.

351
00:16:36.159 --> 00:16:37.879
<v Speaker 2>Which is highly computationally efficient.

352
00:16:37.919 --> 00:16:43.039
<v Speaker 1>Yeah, exactly, But Standard error Descriptor two is unbuffered. Every

353
00:16:43.080 --> 00:16:46.480
<v Speaker 1>single character is transmitted the exact millisecond it is generated.

354
00:16:47.000 --> 00:16:48.480
<v Speaker 1>Why treat the errors differently?

355
00:16:48.679 --> 00:16:50.240
<v Speaker 2>It comes down to crash survival.

356
00:16:50.480 --> 00:16:51.480
<v Speaker 1>Crash survival.

357
00:16:51.639 --> 00:16:56.480
<v Speaker 2>Yeah, imagine a program encounters a catastrophic fatal error. It

358
00:16:56.559 --> 00:17:00.639
<v Speaker 2>generates an error message detailing exactly what went wrong. But

359
00:17:00.720 --> 00:17:03.000
<v Speaker 2>if that message goes into a buffer bucket and the

360
00:17:03.039 --> 00:17:05.920
<v Speaker 2>program crashes before the bucket gets dumped, the bucket just

361
00:17:06.000 --> 00:17:10.599
<v Speaker 2>vanishes exactly that error message is destroyed in memory. You're

362
00:17:10.720 --> 00:17:13.559
<v Speaker 2>left staring at a dead program with zero clues as

363
00:17:13.559 --> 00:17:14.279
<v Speaker 2>to why it died.

364
00:17:14.480 --> 00:17:15.440
<v Speaker 1>That makes total sense.

365
00:17:15.680 --> 00:17:19.519
<v Speaker 2>By making standard error entirely unbeffored, the system guarantees that

366
00:17:19.559 --> 00:17:22.880
<v Speaker 2>the diagnostic text prints to your screen instantly. Even if

367
00:17:22.920 --> 00:17:25.880
<v Speaker 2>the program violently terminates a fraction of a millisecond later,

368
00:17:26.359 --> 00:17:28.440
<v Speaker 2>the error message has already made it out safely.

369
00:17:28.559 --> 00:17:32.519
<v Speaker 1>It prioritizes survival of the forensic data over efficiency. I

370
00:17:32.559 --> 00:17:34.480
<v Speaker 1>love that. And you know, if a program is just

371
00:17:34.519 --> 00:17:36.599
<v Speaker 1>obnoxiously chatty and you don't want to see its output

372
00:17:36.640 --> 00:17:39.400
<v Speaker 1>or save it. You can just redirect the stream to devnel.

373
00:17:39.599 --> 00:17:41.559
<v Speaker 2>Ah. Yes, the bitbucket.

374
00:17:41.839 --> 00:17:44.400
<v Speaker 1>It's a literal black hole where data goes to be

375
00:17:44.440 --> 00:17:48.920
<v Speaker 1>permanently deleted. So okay, we've mastered basic plumbing. We can

376
00:17:49.039 --> 00:17:52.480
<v Speaker 1>route output and errors to files or black holes. But

377
00:17:52.559 --> 00:17:56.319
<v Speaker 1>a shell's real power isn't just shuffling data into files, right,

378
00:17:56.720 --> 00:17:58.000
<v Speaker 1>it's chaining tools together.

379
00:17:58.240 --> 00:18:03.000
<v Speaker 2>Yes, this is where we introduce pipes, represented by the vertical.

380
00:18:02.640 --> 00:18:03.960
<v Speaker 1>Bar character the pipe.

381
00:18:04.000 --> 00:18:06.480
<v Speaker 2>A pipe takes the standard output of one command and

382
00:18:06.480 --> 00:18:09.279
<v Speaker 2>plugs it directly into the standard input of the next command.

383
00:18:09.559 --> 00:18:12.319
<v Speaker 2>But the mechanism of how they execute is what makes

384
00:18:12.359 --> 00:18:15.079
<v Speaker 2>them so powerful. A pipe does not act like a

385
00:18:15.119 --> 00:18:17.559
<v Speaker 2>relay race. What do you mean by that, Well, it

386
00:18:17.599 --> 00:18:19.839
<v Speaker 2>does not wait for the first program to finish its job,

387
00:18:20.079 --> 00:18:22.559
<v Speaker 2>save the data, and hand a completed file over to

388
00:18:22.599 --> 00:18:25.359
<v Speaker 2>the second program. A pipe is an assembly line.

389
00:18:25.440 --> 00:18:26.640
<v Speaker 1>Oh, they run at the same time.

390
00:18:26.839 --> 00:18:30.759
<v Speaker 2>Both programs launch and run simultaneously. The first program writes

391
00:18:30.799 --> 00:18:33.799
<v Speaker 2>data into a shared memory buffer, and the second program

392
00:18:33.839 --> 00:18:36.880
<v Speaker 2>continuously reads from that exact same buffer in real time.

393
00:18:37.079 --> 00:18:40.279
<v Speaker 1>That parallel processing is why the command line can handle

394
00:18:40.359 --> 00:18:43.880
<v Speaker 1>massive data sets. So quickly. You aren't constantly reading and

395
00:18:43.920 --> 00:18:45.759
<v Speaker 1>writing temporary files.

396
00:18:45.359 --> 00:18:47.359
<v Speaker 2>To the hard drive exactly. It's all in memory.

397
00:18:47.559 --> 00:18:51.200
<v Speaker 1>But because data flows too easily, the cookbook mentions, users

398
00:18:51.240 --> 00:18:53.720
<v Speaker 1>often fall into a trap called the useless use of

399
00:18:53.839 --> 00:18:54.440
<v Speaker 1>cat award.

400
00:18:54.640 --> 00:18:55.680
<v Speaker 2>Oh this is a classic.

401
00:18:55.839 --> 00:18:58.599
<v Speaker 1>Yeah, so, pat is a simple command designed to concatenate

402
00:18:58.680 --> 00:19:03.039
<v Speaker 1>files and dump their content to standard output. Beginners constantly

403
00:19:03.119 --> 00:19:05.160
<v Speaker 1>use cat to open a file and then pipe that

404
00:19:05.240 --> 00:19:08.119
<v Speaker 1>text into a search tool like grep, but GP is

405
00:19:08.200 --> 00:19:11.880
<v Speaker 1>fully capable of reading the file directly. The pipe is

406
00:19:11.920 --> 00:19:14.680
<v Speaker 1>just burning CPU cycles for absolutely no reason.

407
00:19:14.839 --> 00:19:19.240
<v Speaker 2>It is although from a purely psychological standpoint, constructing commands

408
00:19:19.240 --> 00:19:21.359
<v Speaker 2>from left to right, starting with the file and then

409
00:19:21.400 --> 00:19:24.680
<v Speaker 2>piping it through various filters, it often aligns better with

410
00:19:24.759 --> 00:19:27.920
<v Speaker 2>how the human brain visualizes a sequence of events.

411
00:19:28.279 --> 00:19:30.880
<v Speaker 1>That's a fair point. It feels more intuitive, but.

412
00:19:30.920 --> 00:19:33.400
<v Speaker 2>Yes, technically it is unnecessary overhead.

413
00:19:33.440 --> 00:19:36.680
<v Speaker 1>Okay, so if we have this beautiful high speed assembly

414
00:19:36.720 --> 00:19:39.440
<v Speaker 1>line of data flowing through pipes, what if we want

415
00:19:39.480 --> 00:19:42.680
<v Speaker 1>to intercept that data without stopping the flow, like tapping

416
00:19:42.680 --> 00:19:45.119
<v Speaker 1>the pipe to check the water quality halfway down the line,

417
00:19:45.240 --> 00:19:45.640
<v Speaker 1>to use.

418
00:19:45.559 --> 00:19:47.960
<v Speaker 2>A t joint a t jup. The command is literally

419
00:19:48.039 --> 00:19:50.839
<v Speaker 2>named t You insert TEA into the middle of your

420
00:19:50.839 --> 00:19:54.240
<v Speaker 2>pipe chain. It reads the data flowing through, saves an

421
00:19:54.240 --> 00:19:56.519
<v Speaker 2>exact copy of it to a text file you specify,

422
00:19:57.039 --> 00:20:01.359
<v Speaker 2>and simultaneously passes the original data completely untouched, down the

423
00:20:01.400 --> 00:20:03.000
<v Speaker 2>pipe to the next program.

424
00:20:03.039 --> 00:20:03.640
<v Speaker 1>Wow.

425
00:20:03.960 --> 00:20:07.640
<v Speaker 2>It's an invaluable tool for debugging a complex multi step

426
00:20:07.759 --> 00:20:11.000
<v Speaker 2>workflow because you can inspect exactly what the data look

427
00:20:11.160 --> 00:20:13.880
<v Speaker 2>like at step three before winn into step four.

428
00:20:14.279 --> 00:20:17.480
<v Speaker 1>That is so useful. Another powerful way to chain things

429
00:20:17.559 --> 00:20:20.400
<v Speaker 1>is command substitution. You wrap a command and a dollar

430
00:20:20.480 --> 00:20:24.079
<v Speaker 1>sign in parentheses. The shell runs the command inside the parentheses,

431
00:20:24.119 --> 00:20:27.960
<v Speaker 1>first captures the output, and pastes that output directly into

432
00:20:27.960 --> 00:20:31.359
<v Speaker 1>your current command line as arguments. For example, you could

433
00:20:31.440 --> 00:20:34.480
<v Speaker 1>use the fine command to locate all temporary files and

434
00:20:34.559 --> 00:20:37.400
<v Speaker 1>use command substitution to instantly feed that list of files

435
00:20:37.400 --> 00:20:38.680
<v Speaker 1>to the ARM command to delete them.

436
00:20:38.759 --> 00:20:42.079
<v Speaker 2>Though you must exercise extreme caution with that. Why because

437
00:20:42.079 --> 00:20:45.079
<v Speaker 2>if your fine command is formulated incorrectly and it returns

438
00:20:45.119 --> 00:20:47.759
<v Speaker 2>a list of critical system files instead of temporary files,

439
00:20:48.039 --> 00:20:50.880
<v Speaker 2>the ARM command will unquestioningly delete.

440
00:20:50.599 --> 00:20:54.359
<v Speaker 1>All of them, oh right, which perfectly transitions us to

441
00:20:54.559 --> 00:20:57.039
<v Speaker 1>conditional execution. We need safety valves.

442
00:20:57.119 --> 00:20:58.559
<v Speaker 2>We definitely do Instead of.

443
00:20:58.480 --> 00:21:01.559
<v Speaker 1>Just running sequences blindly, we can use the double Ampersand

444
00:21:02.079 --> 00:21:05.400
<v Speaker 1>if you put two ampersands between commands, you are telling

445
00:21:05.440 --> 00:21:08.680
<v Speaker 1>the shell run the second command only if the first

446
00:21:08.720 --> 00:21:09.799
<v Speaker 1>command succeeds.

447
00:21:10.000 --> 00:21:13.799
<v Speaker 2>The quintessential example of this is changing directories before initiating

448
00:21:13.839 --> 00:21:20.160
<v Speaker 2>a deletion. Okay, consider the command CD nir roma. The

449
00:21:20.200 --> 00:21:23.160
<v Speaker 2>shell attempts the CD command first. Let's say the nie

450
00:21:23.200 --> 00:21:26.480
<v Speaker 2>kaik befolder was accidentally deleted yesterday, or you simply misscalded.

451
00:21:27.039 --> 00:21:30.039
<v Speaker 2>The CD command fails and throws an error code, and

452
00:21:30.079 --> 00:21:33.200
<v Speaker 2>then what the double ampersand sees that failure and instantly

453
00:21:33.200 --> 00:21:35.880
<v Speaker 2>aborts the entire chain. If you had just separated those

454
00:21:35.920 --> 00:21:38.599
<v Speaker 2>commands with a basic semicolon, the shell would shrug at

455
00:21:38.640 --> 00:21:41.799
<v Speaker 2>the failed CD command blindly, move on to ourre and

456
00:21:41.839 --> 00:21:44.960
<v Speaker 2>proceed to delete every single file in whatever directory you

457
00:21:45.039 --> 00:21:45.960
<v Speaker 2>currently happen to be.

458
00:21:45.880 --> 00:21:48.279
<v Speaker 1>Standing in, which could be catastrophian exactly.

459
00:21:48.599 --> 00:21:50.920
<v Speaker 2>The amper sans check the exit status, and if it

460
00:21:50.960 --> 00:21:54.359
<v Speaker 2>isn't a zero, which mathematically indicates success in Unix, it

461
00:21:54.440 --> 00:21:55.319
<v Speaker 2>halts the execution.

462
00:21:55.640 --> 00:21:58.240
<v Speaker 1>And speaking of preventing disasters, what about the most common

463
00:21:58.279 --> 00:22:01.440
<v Speaker 1>mistake of all you tie but greater than sign to

464
00:22:01.519 --> 00:22:04.920
<v Speaker 1>redirect some output, but you accidentally type the name of

465
00:22:04.960 --> 00:22:09.480
<v Speaker 1>an incredibly important file that already exists. Yeah, the shell

466
00:22:09.519 --> 00:22:12.720
<v Speaker 1>will instantly overwrite your important file with the new data,

467
00:22:12.880 --> 00:22:15.160
<v Speaker 1>permanently destroying the old contents.

468
00:22:15.200 --> 00:22:17.440
<v Speaker 2>Well, you can configure a safety net for that by

469
00:22:17.440 --> 00:22:21.480
<v Speaker 2>typing set toch no clauber into your terminal no clawber. Yeah.

470
00:22:21.519 --> 00:22:25.079
<v Speaker 2>This instructs Bash to strictly refuse to overwrite any existing

471
00:22:25.119 --> 00:22:27.799
<v Speaker 2>file if you use a standard redirection symbol.

472
00:22:28.000 --> 00:22:30.279
<v Speaker 1>But what if I'm completely sure I want to overwrite it?

473
00:22:30.319 --> 00:22:32.279
<v Speaker 1>Like what if I am updating a log file and

474
00:22:32.319 --> 00:22:33.640
<v Speaker 1>I know exactly what I'm doing.

475
00:22:33.759 --> 00:22:36.000
<v Speaker 2>You don't have to turn the safety net off. You

476
00:22:36.160 --> 00:22:39.640
<v Speaker 2>just use the override syntax a greater than sign followed

477
00:22:39.680 --> 00:22:41.720
<v Speaker 2>immediately by a vertical bar. Oh.

478
00:22:41.839 --> 00:22:42.200
<v Speaker 1>Okay.

479
00:22:42.319 --> 00:22:44.720
<v Speaker 2>That vertical bar is a direct command to the shell

480
00:22:45.200 --> 00:22:48.279
<v Speaker 2>to ignore the no clabber rule for this specific execution.

481
00:22:48.920 --> 00:22:51.680
<v Speaker 2>It shares the same imperative do it anyway, regardless of

482
00:22:51.680 --> 00:22:55.000
<v Speaker 2>the consequences, spirited the exclamation point that you'd use to

483
00:22:55.079 --> 00:22:57.440
<v Speaker 2>force actions in the vitext editor.

484
00:22:57.720 --> 00:23:00.359
<v Speaker 1>Okay. I have to push back on one final concept

485
00:23:00.400 --> 00:23:03.599
<v Speaker 1>from the cookbook, though, because it just seems unnecessarily complicated,

486
00:23:03.640 --> 00:23:05.759
<v Speaker 1>All right, what is it? They dedicate a whole section

487
00:23:05.839 --> 00:23:10.000
<v Speaker 1>to here documents. This involves using two less than signs

488
00:23:10.039 --> 00:23:13.559
<v Speaker 1>and a marker word like eof to embed large blocks

489
00:23:13.559 --> 00:23:17.359
<v Speaker 1>of raw texts directly inside the code of a shell script.

490
00:23:18.039 --> 00:23:18.599
<v Speaker 2>Hu docs.

491
00:23:18.960 --> 00:23:21.839
<v Speaker 1>Why go through the trouble of embedding data directly into

492
00:23:21.880 --> 00:23:24.720
<v Speaker 1>the script with weird boundary tags? Why not just keep

493
00:23:24.720 --> 00:23:27.240
<v Speaker 1>your data in a clean, separate text file and have

494
00:23:27.359 --> 00:23:28.319
<v Speaker 1>the script read from.

495
00:23:28.160 --> 00:23:31.920
<v Speaker 2>That file because of the elegance of portability portability. Imagine

496
00:23:31.960 --> 00:23:35.359
<v Speaker 2>you write a script that requires a small static lookup table,

497
00:23:35.640 --> 00:23:39.200
<v Speaker 2>perhaps a list of server IP addresses or basic configuration values.

498
00:23:39.960 --> 00:23:42.319
<v Speaker 2>If you keep that data in a separate file, you

499
00:23:42.400 --> 00:23:43.839
<v Speaker 2>now have two files to manage.

500
00:23:43.960 --> 00:23:44.359
<v Speaker 1>True.

501
00:23:44.519 --> 00:23:46.640
<v Speaker 2>If you email the script to a colleague, you have

502
00:23:46.680 --> 00:23:48.960
<v Speaker 2>to remember to attach the data file. If you move

503
00:23:49.039 --> 00:23:52.160
<v Speaker 2>the script to a different folder, the hard coded filepath breaks.

504
00:23:52.640 --> 00:23:55.440
<v Speaker 2>A here document allows you to package the executable code

505
00:23:55.640 --> 00:23:59.720
<v Speaker 2>and the necessary static data into one single, self contained unit.

506
00:24:00.279 --> 00:24:02.720
<v Speaker 2>It guarantees the script always has the data it needs

507
00:24:02.720 --> 00:24:03.079
<v Speaker 2>to run.

508
00:24:03.160 --> 00:24:05.599
<v Speaker 1>Okay, that does make sense from a distribution standpoint, but

509
00:24:05.640 --> 00:24:09.000
<v Speaker 1>the cookbook highlights a really bizarre Parson quirk with these

510
00:24:09.240 --> 00:24:11.640
<v Speaker 1>here documents that can just ruin your data.

511
00:24:11.799 --> 00:24:13.480
<v Speaker 2>Oh, the variable expansion issue.

512
00:24:13.559 --> 00:24:16.920
<v Speaker 1>Yes, Let's say I'm writing a script that generates a report,

513
00:24:17.000 --> 00:24:19.519
<v Speaker 1>and inside my embedded text block, I write a line

514
00:24:19.559 --> 00:24:22.160
<v Speaker 1>that says pete one hundred dollars to represent a donation.

515
00:24:22.480 --> 00:24:25.519
<v Speaker 1>Right when the script actually runs and prints the text,

516
00:24:25.720 --> 00:24:29.839
<v Speaker 1>it spits out pete zero zero, the one completely vanished.

517
00:24:30.079 --> 00:24:30.720
<v Speaker 1>Where did it go?

518
00:24:31.359 --> 00:24:33.839
<v Speaker 2>Well, this is where understanding the shell's order of operations

519
00:24:33.880 --> 00:24:37.880
<v Speaker 2>is vital. By default, the shell looks inside the here

520
00:24:37.960 --> 00:24:41.400
<v Speaker 2>document and expands any variables it recognizes before it does

521
00:24:41.400 --> 00:24:42.000
<v Speaker 2>anything else.

522
00:24:42.200 --> 00:24:44.359
<v Speaker 1>Oh, so it sees the dollar sign exactly.

523
00:24:44.440 --> 00:24:46.599
<v Speaker 2>It scans your text and seas one hundred dollars. It

524
00:24:46.640 --> 00:24:49.480
<v Speaker 2>interprets the one dollar as a variable representing the first

525
00:24:49.559 --> 00:24:52.039
<v Speaker 2>argument pass to the script. And if you just ran

526
00:24:52.079 --> 00:24:55.440
<v Speaker 2>the script normally without passing any arguments, one dollar is

527
00:24:55.480 --> 00:24:59.440
<v Speaker 2>completely empty. So the shell dynamically replaces the one dollar

528
00:24:59.519 --> 00:25:02.240
<v Speaker 2>with nothing, leaving only the two trailing zeros.

529
00:25:02.440 --> 00:25:05.119
<v Speaker 1>So my one hundred dollars string is silently mutated into

530
00:25:05.240 --> 00:25:08.000
<v Speaker 1>zero dollars. How do you stop the shell from doing that?

531
00:25:08.119 --> 00:25:09.519
<v Speaker 2>With one single backslash?

532
00:25:09.839 --> 00:25:11.000
<v Speaker 1>Just a backslash?

533
00:25:11.119 --> 00:25:13.319
<v Speaker 2>Yep, When you declare the start of your hearge document.

534
00:25:13.359 --> 00:25:18.000
<v Speaker 2>Instead of typing eof you type eof. That single backslash

535
00:25:18.319 --> 00:25:21.240
<v Speaker 2>acts as a master switch. It signals the shell to

536
00:25:21.240 --> 00:25:25.359
<v Speaker 2>completely disable variable expansion inside the document block. Wow, the

537
00:25:25.359 --> 00:25:29.240
<v Speaker 2>shell is forced to treat everything inside as raw literal text.

538
00:25:29.680 --> 00:25:33.359
<v Speaker 2>One keystroke completely changes how the entire script parses the data.

539
00:25:33.839 --> 00:25:36.799
<v Speaker 1>So what does this all mean? We started today by

540
00:25:36.839 --> 00:25:39.519
<v Speaker 1>stepping through that hidden door, pulling back the curtain on

541
00:25:39.559 --> 00:25:43.599
<v Speaker 1>what a shell actually is, a swappable interface entirely separated

542
00:25:43.599 --> 00:25:46.240
<v Speaker 1>from the heavy lifting kernel. We learned how to map

543
00:25:46.279 --> 00:25:49.559
<v Speaker 1>this new environment using the path variable. Discovering the very

544
00:25:49.640 --> 00:25:53.160
<v Speaker 1>real security threats that dictate how folders are ordered. We

545
00:25:53.279 --> 00:25:56.599
<v Speaker 1>challenge the everything is a file mantra, only to realize

546
00:25:56.640 --> 00:25:59.440
<v Speaker 1>that treating hardware as simple byte streams is what enables

547
00:25:59.519 --> 00:26:02.839
<v Speaker 1>us to build massive plumbing networks. With file descriptors, we

548
00:26:02.960 --> 00:26:06.480
<v Speaker 1>unpacked the survival mechanics of unbuffered error streams, and we

549
00:26:06.519 --> 00:26:09.799
<v Speaker 1>connect it all with parallel processing pipes, t joints, and

550
00:26:09.880 --> 00:26:13.799
<v Speaker 1>strict conditional logic. It means that by understanding a few

551
00:26:13.920 --> 00:26:19.200
<v Speaker 1>simple underlying mechanisms, you can combine tiny specialized commands into

552
00:26:19.279 --> 00:26:23.960
<v Speaker 1>incredibly powerful automated workflows. You are no longer just a

553
00:26:24.000 --> 00:26:27.000
<v Speaker 1>passenger clicking through menus on your computer. You are the

554
00:26:27.079 --> 00:26:29.920
<v Speaker 1>mechanic who understands the wiring, which.

555
00:26:29.799 --> 00:26:33.240
<v Speaker 2>Leads to a rather profound realization about the current trajectory

556
00:26:33.279 --> 00:26:35.759
<v Speaker 2>of modern computing. Oh, we are living in an era

557
00:26:35.839 --> 00:26:39.160
<v Speaker 2>where tech companies are racing to build AI driven interfaces

558
00:26:39.559 --> 00:26:42.119
<v Speaker 2>that attempt to guess what you want. They're designed to

559
00:26:42.160 --> 00:26:46.240
<v Speaker 2>interpret your vague intentions, smooth over your mistakes, and execute

560
00:26:46.279 --> 00:26:47.240
<v Speaker 2>tasks on your behalf.

561
00:26:47.519 --> 00:26:49.480
<v Speaker 1>That's definitely the trend right now.

562
00:26:49.400 --> 00:26:52.519
<v Speaker 2>Right, But the command line remains the exact polar opposite

563
00:26:52.559 --> 00:26:55.759
<v Speaker 2>of that trend. It is brutally literal. It does exactly

564
00:26:55.839 --> 00:26:57.480
<v Speaker 2>what you tell it to do, no more, no less,

565
00:26:57.720 --> 00:26:59.559
<v Speaker 2>even if what you tell it to do is catastrophic.

566
00:26:59.640 --> 00:27:01.559
<v Speaker 1>Yeah, we definitely saw that with the root access and

567
00:27:01.599 --> 00:27:03.160
<v Speaker 1>the overriting exactly.

568
00:27:03.319 --> 00:27:06.400
<v Speaker 2>So it forces us to ask a difficult question. As

569
00:27:06.440 --> 00:27:11.759
<v Speaker 2>our daily interfaces become smarter, more predictive, and vastly more abstract,

570
00:27:11.799 --> 00:27:15.160
<v Speaker 2>what fundamental computing powers and deep understandings of our own

571
00:27:15.200 --> 00:27:17.480
<v Speaker 2>machines are we voluntarily giving up?

572
00:27:17.599 --> 00:27:20.759
<v Speaker 1>Wow? If we rely entirely on the graphical illusions and

573
00:27:20.799 --> 00:27:24.000
<v Speaker 1>the predictive guessing games, we inevitably forget how the underlying

574
00:27:24.039 --> 00:27:27.119
<v Speaker 1>engine actually works. We hand over the master keys. You do,

575
00:27:27.400 --> 00:27:29.359
<v Speaker 1>but for today, at least you have a few more

576
00:27:29.480 --> 00:27:32.160
<v Speaker 1>raw commands in your back pocket to ensure that doesn't happen.

577
00:27:32.720 --> 00:27:36.079
<v Speaker 1>Stay curious, keep exploring that blank screen, and thanks for

578
00:27:36.119 --> 00:27:37.720
<v Speaker 1>taking the deep dive with us today
