Save this video free

Lecture 12: Conditional statements

Burton Ma · 47:10 · Watch on YouTube

Part of Queen's University CISC220. See all 23 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Burton Ma explains Bash conditional statements by showing that an `if` condition is evaluated through a command’s exit status: zero means true, and nonzero means false. He demonstrates `[[ ... ]]` tests for variables, files, and strings; explains glob-pattern matching and redirection; and recommends `(( ... ))` for numeric comparisons and compound arithmetic conditions.

Key takeaways

Chapters

0:00 Bash `if` Syntax and Exit-Status Conditions
4:00 Using `cd` as a Condition and Quoting Directory Arguments
12:00 Sending Script Errors to Standard Error and `/dev/null`
15:30 Bash `[[ ... ]]` Tests and ShellCheck
20:00 Variable Assignment and File Tests in `[[ ... ]]`
25:00 String Tests, Glob Patterns, and Regular Expressions
30:00 Integer Comparisons and Argument-Count Validation
37:00 Combining Conditions with Negation, AND, and OR
43:20 Testing Leap Years with Arithmetic Conditions

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

Transcript excerpt

0:02 So um we're nearing the end of the bash content of the course. So all we got left are if statements, loops, and uh functions. So we should be done all of this before reading week. Which means we'll transition into C after reading week. Um right. So today's uh lecture is about conditional statements or if statements. Right? So we've seen um some examples of if statements already in the course. Right? Uh we've seen simple examples of if statements. In general, the if statement in bash looks like what's shown to you on the screen right now. Um so the keywords are if then uh elif for else if else for else and then of course the if statement ends with the fee fi. Uh the

0:54 if statement in bash works like an if statement in most other programming languages. If this condition is true, then these sets of commands get run and then you jump to the end of the if statement. Right? If that first condition is not true, then the second condition gets tested. If that condition is true, those commands run and then you jump to the end of the if statement. You can have multiple else if clauses. So you can have as many el oops, sorry. You can have as many elif clauses as you want or require. uh in bash the semicolon is the uh standard cell s uh symbol used to separate sequences of commands. Um so you can write the if statement like this if you like. This is the way I normally write it. It doesn't matter if you write it this way or if you want to

1:42 write it this way. So you can always write it without the semicolon. You just have to put the then or the yeah the

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

In this course

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.