Save this video free

Lecture 8: Arithmetic; Variables

Burton Ma · 52:28 · Watch on YouTube

Lecture 8: Arithmetic; Variables Watch on YouTube →

Overview

Burton Ma explains Bash scripting through exit statuses, special parameters, integer arithmetic, conditionals, random numbers, and variable expansion. Key practical lessons include checking command-line argument counts, sending errors to standard error, and using braces to avoid ambiguous variable names; Bash also treats unset variables as empty strings and nonnumeric arithmetic values as zero.

Key takeaways

Chapters

0:00 Bash Script Structure and Command Exit Status
5:00 Bash Comments and Special Parameters
8:30 Inspecting Script Arguments with $#, $0, and Positional Parameters
13:00 Unset Bash Variables Become Empty Strings
17:00 Integer Arithmetic with Bash Double Parentheses
21:00 Nonnumeric Arithmetic and Arithmetic Command Status
26:40 Argument Validation, Standard Error, and Exit
31:40 Generating Bounded Random Integers with RANDOM
37:20 Bash Variables, Assignment, and String Expansion
44:00 Environment Variables, Quoting, and Braces for Safe Expansion

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:06 Right, good afternoon everybody. Um, so in the previous lecture we were talking about writing a bash script which is just a program written in bash. All right. All right. So, remember the first thing you have to keep in mind is that uh the first line of your script is always going to include the uh interpreter directive hashbang rootbin bash if you're in Linux, right? And this just tells uh your shell that when you run this as a command, you want to use bash um as the interpreter for the rest of the script. If you're on a Mac, you probably want to use the following instead, right? So, hashbang userbin envash that says the same thing just in a wordier way um and in a way such that on

0:55 most of your machines if you set it up properly or according to how the course uh instructions told you you get the proper version of bash to run your program right after that the rest of your script just contains a sequence of bash commands all right so bash is both a shell and a programming language language. So like most other programming languages, Bash has a comment, right? So the comment in Bash is the exact same as in Python. It's just the hash symbol. And so that line right there is a comment, right? The first line is not a comment, right? So if the hash symbol appears on the first line as the first character, it's not a comment. It's the interpreter directive, right? Everywhere else, right? It's a comment. So that's also a

1:42 comment. And so this uh script Looks like it should do nothing, right? And that's what the comment says. It says this program does nothing. Almost, right? And so the almost uh is

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Burton Ma.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.