Lecture Notes

Learning assistant supported notes for CS 35L


Project maintained by UCLA-CS-35L Hosted on GitHub Pages — Theme by mattgraham

Little Languages

Remark. Think of programming as contained lots of little domains within each language. Bash/shell is sort of its own domain: you’ll want to understand how to combine programs together. Regular expressions are also their own domain: you’ll want to understand how to match certain patterns of text.

For example, consider the command grep.


Aside. Professor Eggert tends to ask cross-domain questions. It lets him think of good, hard questions.


Regular Expressions Intro

Different regular expression engines will have different flavors. Typically, there are three main categories: basic (BRE), extended (ERE), and Perl compatible (PCRE). In this course, we’ll focus on BRE and ERE since grep supports this. You may assume that we are using GNU grep; other operating systems (e.g. MacOS) and programming languages (e.g. JavaScript) may have their own built-in extensions.


Aside. Once you understand how to write regular expressions, try experimenting with -l, -L, -lv, and -Lv. Inverting with -v and inverting in bracket expressions with ^ are also different.


Extended Regular Expressions (EREs)


Aside. EREs are better (even Professor Eggert has said so in the past), so just use grep -E when possible.


Example: match lines that contain at least one “a” and no “b”s.

Basic Regular Expressions (BREs)

BRE syntax just requires you to replace escape the special characters ?+{|( to get their special meaning.

Bash Scripting Intro

All scripts start with a shebang. This is the first line and starts with #!. The shebang indicates what program we will use to interpret the text below.

Common Bash Constructs

The following are common constructs when writing scripts in Bash.


Aside. This section will be updated once I have a clearer idea of what Professor Eggert wants to lecture about with Bash. Historically, many Bash scripts ended up being one-liners. Discussion slides will definitely talk about Bash.


Bash Quoting and Escaping


Aside. This section will be updated or removed once I have a clearer idea of what Professor Eggert wants to lecture about with Bash.