Speaker 1: I want you to I want you to picture a garage,
Speaker 1: like a really high end modern.
Speaker 2: Garage, Okay, I'm picturing it.
Speaker 1: And on the left side, you've got the absolute cutting
Speaker 1: edge of automotive engineering. Let's say a brand new, gleaming
Speaker 1: Tesla or maybe Elucid Air.
Speaker 2: Right, something really sleek, exactly.
Speaker 1: It's got the self driving AI, the massive touch screens,
Speaker 1: the over the air updates. It is the future.
Speaker 2: It's sexy. It's what everyone wants to drive right now, right, and.
Speaker 1: That represents modern coding languages, your Python, your rust go
Speaker 1: things like that. Yeah, But then I want you to
Speaker 1: look over to the right side of this garage. O.
Speaker 1: Sitting on cinder blocks covered in maybe forty years of dust,
Speaker 1: is a rusted out Model T Ford. It looks like
Speaker 1: it belongs in a museum, sounds out a place. It does.
Speaker 1: But here's the twist. You pop the hood of that
Speaker 1: shiny k need Tesla and the engine inside it. It's
Speaker 1: the Model T engine.
Speaker 2: That is a terrifying image, honestly, but it's painfully accurate.
Speaker 1: It really is. Yeah, Because we're ta talking go to
Speaker 1: technology that feels ancient, almost prehistoric in computer years, yet
Speaker 1: it is currently running the back end of your bank.
Speaker 1: It's the logistics system delivering your packages.
Speaker 2: And crucially, it is installed on every single Windows computer in.
Speaker 1: Existence right now, Yes, every single one.
Speaker 2: We are talking about batch scripting. I've heard it called
Speaker 2: the cockroach of the IT world.
Speaker 1: Cockroach feels a little harsh, but I kind of get it.
Speaker 1: It just won't die.
Speaker 2: It won't, and honestly it shouldn't. It's way too integrated
Speaker 2: into the bedrock of our digital infrastructure.
Speaker 1: So today we're doing a deep dive into a really
Speaker 1: fascinating source. It's called the Book of Batch Scripting From
Speaker 1: Fundamentals to Advance Automation by Jack McLarney. It's great read,
Speaker 1: it is, and the mission for this deep dive is
Speaker 1: pretty clear. We want to figure out why this nineteen
Speaker 1: eighties technology, which is rooted in MS doos, is still
Speaker 1: so vital.
Speaker 2: But we also need to warn you. McLarney makes it
Speaker 2: very clear in the book that batch is a minefield.
Speaker 2: Oh absolutely, it's powerful, but it is just full of traps.
Speaker 2: He actually coins a term for this, which I absolutely love.
Speaker 2: He calls them bat beats. Bat beats, yeah, like caveats,
Speaker 2: but specific to batch. A bat beat is basically a
Speaker 2: quirk or a trap in the language that just doesn't
Speaker 2: exist in modern coding.
Speaker 1: Right because modern languages have safety rails exactly.
Speaker 2: But in Batch, the interpreter is incredibly literal or sometimes
Speaker 2: just plain weird in a way that can completely destroy
Speaker 2: your entire workflow if you aren't careful.
Speaker 1: And we have a list of the nastiest ones to
Speaker 1: get through today, we're going to look at the space trap,
Speaker 1: the Octal Horror Story, which is my absolute.
Speaker 2: Favorite, by the way, oh it's a classic.
Speaker 1: And the inception logic of nested variables. But let's start
Speaker 1: with the basics what the book calls the wild West
Speaker 1: of variables.
Speaker 2: The wild West is definitely the right way to put it.
Speaker 2: There is no sheriff in this town at all.
Speaker 1: So in most languages, if I want to write code,
Speaker 1: I have to be specific. I tell the computer, Hey,
Speaker 1: this variable is a number, or this variable is a
Speaker 1: string of text. There were rules.
Speaker 2: Batch doesn't care about any of that, not at all.
Speaker 2: In Batch, everything is created x nihilo out of nothing. Intrinsically,
Speaker 2: to the Batch interpreter, everything is just a string of bytes.
Speaker 2: It doesn't know the difference between the number five and
Speaker 2: the word five.
Speaker 1: Until you force it to do math, which leads to
Speaker 1: what I think is the most infuriating yet kind of
Speaker 1: hilarious rookie mistake in the book The Space Trap.
Speaker 2: Oh Man, the Space Trap. This is a classic batv.
Speaker 2: I have seen grown engineers, people with master's degrees, completely
Speaker 2: pull their hair out over this.
Speaker 1: So walk us through this. Let's say I want to
Speaker 1: set a variable named x to the value hello.
Speaker 2: Okay.
Speaker 1: In a normal language, being a tidy person who likes
Speaker 1: readable code, I might type set x, then a space,
Speaker 1: an equal sign, another space, and then hello. I put
Speaker 1: spaces around the equal sign because it looks nice.
Speaker 2: It's clean, right, And in Python our JavaScript, that's fine.
Speaker 2: The computer ignores the white space. That knows what you mean.
Speaker 2: But the batch interpreter it is aggressively literal.
Speaker 1: Aggressively literal.
Speaker 2: Yes, if you type set x space equal space hello,
Speaker 2: the interpreter doesn't say, oh they want x to equal hello,
Speaker 2: does it do? It reads exactly what you typed. It
Speaker 2: sees the space before the equal sign and includes it
Speaker 2: in the name. So now you have a variable named
Speaker 2: x space.
Speaker 1: Wait xspace literally.
Speaker 2: Literally, and then it sees the space after the equal
Speaker 2: sign and includes that in the value. So the value
Speaker 2: isn't Hello, it's space Hello.
Speaker 1: So I haven't said X to hello at all. I've
Speaker 1: set x space to space hello exactly.
Speaker 2: And here is the kicker. If you try to use
Speaker 2: that variable later by calling just x, which is what
Speaker 2: you think you named it, it won't work because X
Speaker 2: doesn't exist, only X space exists.
Speaker 1: That is maddening. And since you can't see a space
Speaker 1: character with the naked eye, you'd be steering at your
Speaker 1: code for hours wondering why it's broken.
Speaker 2: Precisely, you're looking at the screen shouting, I defined X.
Speaker 2: It's right there. But you didn't define X. You defined
Speaker 2: x space.
Speaker 1: Wow.
Speaker 2: That's why their author mcclerney practically begs you to stop
Speaker 2: using basic notepad. You need an editor like Notepad plas
Speaker 2: plus where you can turn on show space and tab.
Speaker 2: You have to see the invisible characters or badge will
Speaker 2: destroy you.
Speaker 1: Okay, So once we've successfully set a variable, you know,
Speaker 1: without the space as, we run into another issue, usefulness.
Speaker 1: Usually when I set a variable and a command prompt,
Speaker 1: it vanishes the second I close the window.
Speaker 2: That's the ephemeral nature of the standard set command. It's
Speaker 2: only a live for that specific session. It's like short
Speaker 2: term memory. Yeah, but mcclarney highlights a tool that I
Speaker 2: think is vastly underused, sex the extreme set Essentially, yes,
Speaker 2: SETX allows you to save a variable into the system
Speaker 2: environment permanently. It actually survives a reboot.
Speaker 1: So why does that matter? Give me a real world
Speaker 1: scenario where i'd use that.
Speaker 2: Imagine you're a developer. You're building an app that needs
Speaker 2: to know where a database is located. You don't want
Speaker 2: to type that really long filepath every single time you
Speaker 2: open a terminal to test your.
Speaker 1: Code, right, That would be pedious.
Speaker 2: So you can use set x to burn that location
Speaker 2: into your machine's environment.
Speaker 1: So it becomes part of the furniture exactly.
Speaker 2: Every time you open your tools, the variable is just there.
Speaker 2: You don't have to retype it. It's a huge time
Speaker 2: saver for setting up development environments. But again, you have
Speaker 2: to be careful because if you set ux a typo,
Speaker 2: that typo is now permanent until you go in and
Speaker 2: fix it.
Speaker 1: High stakes, high reward. Okay, so we've got our variables,
Speaker 1: we're avoiding spaces. Now we need to talk about the
Speaker 1: segment that actually made me laugh out loud while reading
Speaker 1: the octal horror story.
Speaker 2: This is the ultimate batbate. It's a story that perfectly
Speaker 2: illustrates how fragile batch logic can be.
Speaker 1: So the setup is this. The author has a script
Speaker 1: that's been running perfectly for six months. It's a date calculator.
Speaker 1: Its job is to figure out the previous.
Speaker 2: Day, right, simple logic. If today is the fifth, yesterday
Speaker 2: was the fourth. If today's the first, we need to
Speaker 2: go back to the previous month.
Speaker 1: And this works beautifully in January, February, March, all the
Speaker 1: way through July. But then August first rolls around the
Speaker 1: day of doom. The script wakes up, tries to calculate
Speaker 1: the previous month. It takes the current month, which is
Speaker 1: August represented as zero eight, and tries to subtract one
Speaker 1: to get July or zero seven. Simple math eight minus one.
Speaker 2: Equal seven, But the script crashes.
Speaker 1: It just implodes why why on Earth would eight minus
Speaker 1: one crash a computer program?
Speaker 2: It comes down to a legacy holdover from the dawn
Speaker 2: of computing, specifically from the C programming language in Unix.
Speaker 2: In Batch, a leading zero on a number is a signal.
Speaker 2: It tells the interpreter we are not using the decimal system.
Speaker 1: The base ten system that humans use.
Speaker 2: Right, it says we are using octal base eight.
Speaker 1: Okay, let's unpack octal. Most listeners probably haven't thought about
Speaker 1: base eight since high school computer science.
Speaker 2: If ever, so, in our normal base ten system, we
Speaker 2: have digit zero through nine. When we get to ten,
Speaker 2: we roll over. In octal, you only have digit zero
Speaker 2: through seven. That's it. There is no eight, there is
Speaker 2: no eight, and there's no nine. In octaal you count
Speaker 2: zero one, two, three, four, five, six, seven, and the
Speaker 2: next number is ten.
Speaker 1: So when the script saw zero eight, it.
Speaker 2: Saw the zero and switched to octal mode. Then it
Speaker 2: saw the eight and panicked. It's like trying to divide
Speaker 2: by zero. To the back interpreter, zero eight is an
Speaker 2: impossible number. It's a hallucination. It just doesn't exist.
Speaker 1: That is wild. So literally, because the date was August
Speaker 1: first on the calendar, the server process died.
Speaker 2: Yes, And the author describes his reaction when he finally
Speaker 2: figured this out. He's looking at the logs, he sees
Speaker 2: the zero eight and he realizes it's the octal bug.
Speaker 2: He just screams oscy tale at the sky.
Speaker 1: He compares it to Captain Kirk screaming con in star
Speaker 1: Trek two.
Speaker 2: I can picture it perfectly, just sheer nerd rage.
Speaker 1: So how do you fix that? Do you just cancel August?
Speaker 2: You have to scrub the data. You use substring tricks
Speaker 2: to look at the date. You say, if the first
Speaker 2: character is a zero, delete it. You have to turn
Speaker 2: zero eight into just eight.
Speaker 1: And once it's eight without the.
Speaker 2: Zero, Batch treats it as a decimal and everything is fine.
Speaker 1: It really reinforces the idea that Batch is just a
Speaker 1: language of workarounds.
Speaker 2: Absolutely, it's ductate all the way down. And that leads
Speaker 2: perfectly into the next topic, faking functionality. Because if you're
Speaker 2: coming from Python or Java, you expect certain things. You
Speaker 2: expect to.
Speaker 1: Have boollions, true or false variables.
Speaker 2: Right, and you expect to have floating point numbers, decimals.
Speaker 1: And Batch has neither none, zero.
Speaker 2: So how do you check if something is true or false?
Speaker 1: You have to diyat. The book shows this clever workaround.
Speaker 1: Instead of setting a variable to the abstract concept of true,
Speaker 1: you set the variable to the string true equals equals true.
Speaker 2: Wait, you set the variable to an actual equation exactly.
Speaker 1: So later when you use an if command, you're basically
Speaker 1: pasting that equation into the command, the interpreter checks does
Speaker 1: the string true equal the string truth? Yes, so the
Speaker 1: condition passes. It's crude, but it works.
Speaker 2: That feels like hot wiring a car to get it started.
Speaker 1: That is Batch in a nutshell, right, And it gets
Speaker 1: even messier with math. Say you want to calculate sales tax.
Speaker 1: You need decimals. You need to multiply by one point
Speaker 1: oh seven. Batch can't do decimals. It truncates everything to
Speaker 1: a whole number.
Speaker 2: So how do you do it? The book mentions a
Speaker 2: spade shovel analogy. Right. Mcclarney says, doing floating point math
Speaker 2: in Batch is like digging a foundation with a spade shovel.
Speaker 2: You can do it, but do you really want to?
Speaker 2: The trick is what he calls digital anarchy. Digital anarchy,
Speaker 2: You take your number, say one point ninety nine, You
Speaker 2: treat it as a string of text. You remove the dot.
Speaker 2: Now you have one ninety nine.
Speaker 1: Okay, so now it's an integer. Batch can handle that, right.
Speaker 2: You do your math on one ninety nine. Let's say
Speaker 2: you double it to three ninety eight. Then you have
Speaker 2: to use substring logic to forcefully paste the decimal point
Speaker 2: back in before the last two digits. So you manually
Speaker 2: turn three ninety eight back into three point ninety eight.
Speaker 1: You are manually managing the decimal point.
Speaker 2: You are the floating point processor. You are doing the
Speaker 2: job the CPU usually does for you.
Speaker 1: That is dedication. But I guess if it's the only
Speaker 1: tool installed on the server, you do what you have
Speaker 1: to do.
Speaker 2: And that brings us to the feature that sounds the
Speaker 2: most intimidating but is actually the secret weapon of Batch
Speaker 2: power users.
Speaker 1: Delayed expansion set local enabled delete expansion. Sounds like a
Speaker 1: cheat code.
Speaker 2: It basically is. To understand why you need it, you
Speaker 2: have to understand how Batch reads code. Normally, Batch reads
Speaker 2: a full line of code or a block of code
Speaker 2: inside parenthesis and parses it all at once.
Speaker 1: Explain that parsing process a bit.
Speaker 2: Think of it like ordering at a restaurant. In a
Speaker 2: normal language, you order appetizers, you eat them, then you
Speaker 2: order the main course. In Batch without delayed expansion, you
Speaker 2: have to order everything appetizers, main dessert the moment you
Speaker 2: sit down.
Speaker 1: So if I change my mind halfway through the meal,
Speaker 1: too bad.
Speaker 2: The order is already in. In coding terms, if you
Speaker 2: change a variable inside a loop and then try to
Speaker 2: read it inside that same loop. The interpreter won't see
Speaker 2: the change. It already decided what that variable was before
Speaker 2: the loop started.
Speaker 1: That seems like a massive design flaw.
Speaker 2: It's just how it's built in the eighties. But enabled
Speaker 2: delayed expansion fixes it. It allows you to use exclamation
Speaker 2: marks instead of percent signs, like exclamation point variable exclamation point.
Speaker 2: This forces the interpreter to.
Speaker 1: Wait, wait for what.
Speaker 2: It tells the interpreter, don't check this variable when you
Speaker 2: take the order, check it when you actually serve the dish.
Speaker 2: It forces the variable to be evaluated at the exact
Speaker 2: moment of execution.
Speaker 1: Hence delayed expansion precisely.
Speaker 2: And this unlocks something really cool that the author compares
Speaker 2: to the movie Inception nested.
Speaker 1: Variables, variables inside variable.
Speaker 2: Yes, with delayed expansion, you can do something like exclamation
Speaker 2: food percent city percent exclamation.
Speaker 1: Okay, let's unpack that. That looks like a typo salad.
Speaker 2: It does, but look at the order of operations. The
Speaker 2: interpreter looks at the percent city percent first. Let's say
Speaker 2: the city variable is Nashville. It resolves that part immediately. Now,
Speaker 2: the overall variable name becomes exclamation food Nashville exclamation ah.
Speaker 1: I see. So it construct the name of the variable
Speaker 1: it wants to find exactly.
Speaker 2: Then it looks up the value of food Nashville, which
Speaker 2: might be hot chicken.
Speaker 1: So you can dynamically change which variable you are looking
Speaker 1: at based on the value of another variable exactly.
Speaker 2: It allows for dynamic coding like arrays and lookups that
Speaker 2: is actually really hard to do in some compiled languages.
Speaker 2: It turns this clunky old scripting language into something surprisingly flexible.
Speaker 1: I love that. It's like finding a secret compartment in
Speaker 1: that rusted out model.
Speaker 2: T a secret compartment that holds a supercomputer.
Speaker 1: So we've covered the logic and the variables. Now we
Speaker 1: need to talk about the heavy lifting moving files, because
Speaker 1: at the end of the day, that's what most people
Speaker 1: use Batch for backups, organizing folders, moving data.
Speaker 2: And there is a clear hierarchy here. It's like an
Speaker 2: evolutionary chart. At the bottom you have the copy command,
Speaker 2: the primitive tool. The expert advice here is simple, do
Speaker 2: not use copy for actual files. It's too basic. It
Speaker 2: stops at the first sign of trouble. Its only real
Speaker 2: use nowadays is concatenation, merging, text files together or creating
Speaker 2: empty files.
Speaker 1: Using the null device, So we graduate to s copy.
Speaker 2: SKP is the workhorse. It's been around forever. It's great
Speaker 2: for single files, and the book highlights two crucial flags
Speaker 2: or options you need to know, slash y and slash F.
Speaker 1: Slash y suppresses the conformation pumped right. Are you sure
Speaker 1: you want to overwrite prompt yes.
Speaker 2: If you are automating a backup that runs at three
Speaker 2: in the morning, you cannot have the script pause to
Speaker 2: ask a question. No one is there to answer it.
Speaker 2: The script will just hang there forever. Slash y just
Speaker 2: says yes to everything, and slash F full paths. It
Speaker 2: forces the LUG to show you exactly where the file
Speaker 2: came from and exactly where it went. Without it, your
Speaker 2: flying blind if something goes wrong.
Speaker 1: But then we reach the final form the robust copy robocopy.
Speaker 2: Robocopy is an absolute beast. It's designed for serious automation.
Speaker 2: It can mirror entire drives, it can resume file transfers
Speaker 2: if the network cuts out. It's incredibly resilient.
Speaker 1: And the logging is intense.
Speaker 2: Oh it's beautiful. Header's speed statistics separate counts for skip files.
Speaker 2: Mismatched files. But there is a batfeat here too. The
Speaker 2: return codes.
Speaker 1: We talked about this before the show. In SAT copy
Speaker 1: a zero means success. Everything is good right.
Speaker 2: In almost all of computing, zero means no error. But
Speaker 2: robocopy it uses powers.
Speaker 1: Of two logicwers of two, So.
Speaker 2: If robic copyer returns to zero, it actually means no errors.
Speaker 2: But I didn't copy anything.
Speaker 1: Wait, so zero is essentially I did nothing right.
Speaker 2: It means the files matched the destination already, so it
Speaker 2: just skipped them.
Speaker 1: Okay.
Speaker 2: If it returns a one, it means I copied one
Speaker 2: or more files successfully.
Speaker 1: Okay, that sounds like success.
Speaker 2: But then you have two four, eight, sixteen, and they
Speaker 2: can be combined. This is bitmasking. So if you get
Speaker 2: a return code of three, that means one files copied
Speaker 2: plus two extra files detected.
Speaker 1: So you literally have to do modulo math just to
Speaker 1: figure out if your backup work you do.
Speaker 2: You can't just check if aer a level equals zero.
Speaker 2: You have to check if the air level is less
Speaker 2: than eight. Essentially, it's bizarre, but it gives you a
Speaker 2: granular level of detail that other commands just don't.
Speaker 1: It seems like that's the theme of this entire deep dive.
Speaker 1: Bizarre but useful, it really is.
Speaker 2: It forces you to think differently.
Speaker 1: Which brings us to the philosophy of the book. Mcclerney
Speaker 1: compares being a batch coder to being a Sumerian priest.
Speaker 2: I love this analogy. He says, reading batch code, especially
Speaker 2: when you get into the messy syntax of four loops
Speaker 2: and delayed expansion, is like reading cuneiform. It looks esoteric,
Speaker 2: it looks cryptic, but if you can read it, you
Speaker 2: have immense power over the machine. You are one of
Speaker 2: the few who can speak the language of the temple.
Speaker 1: And he quotes Woody Guthrie in the epigraph. Any fool
Speaker 1: can make something complicated, it takes a genius to make
Speaker 1: it simple.
Speaker 2: Batch force is simplicity. You don't have libraries, you don't
Speaker 2: have fancy IDEs helping you out. You have raw text commands.
Speaker 2: You are forced to strip the problem down to its
Speaker 2: bare metal logic. And there is something deeply satisfying about that.
Speaker 1: It's digital minimalism.
Speaker 2: It is, and the barrier to entry is zero. That's
Speaker 2: the most important takeaway.
Speaker 1: You don't need to install Python, you don't need to
Speaker 1: set up a compiler, right now you.
Speaker 2: Can open notepad, you can type echo Hello world, you
Speaker 2: can save it as dot bat, and when you double
Speaker 2: click it, you have written a program. You are officially
Speaker 2: a programmer.
Speaker 1: It's the garage door opener to the world.
Speaker 2: Of codev And honestly, if you can master the logic
Speaker 2: of preventing an octal crash or figuring out robocopy bit masks,
Speaker 2: you can learn any other language easily. Batch teaches you
Speaker 2: to think like the computer.
Speaker 1: So here is a final thought for you to chew on.
Speaker 1: We talked about how a simple date August first, could
Speaker 1: crash a server because of a tiny logic quirk, and
Speaker 1: how a number is interpreted.
Speaker 2: The octal bug.
Speaker 1: It makes you wonder what other invisible logic is running
Speaker 1: the world right now. How many banking systems or traffic
Speaker 1: lights or power grids are running on a dot bat
Speaker 1: file written in nineteen ninety five, just waiting for a
Speaker 1: specific date or a specific file name to trigger a
Speaker 1: hidden trap.
Speaker 2: That is a terrifying thought. The digital infrastructure of the
Speaker 2: world is held together by duct tape and set local
Speaker 2: enabled delayed expansion.
Speaker 1: And on that note, maybe go check your backups. Thanks
Speaker 1: for diving in with
Speaker 2: Us always a pleasure,