Link Search Menu Expand Document

Homework 00: Course Overview + The Shell

Every week, there will be ~5 homework problems submitted via Gradescope. There will also be optional open-ended questions, like “try using X and Y programs.” We highly encourage you to try them out. Homework solutions will be posted after the deadline, but open-ended questions may not have solutions.

Gradescope add code: D5BNJW

Homework Setup

We will be using Git to set up your homework assignments. Some of you may be unfamiliar with this tool, and that’s okay! We will be covering how this tool works in future lessons. For now, follow the instructions below in your shell to download the assignments. (If you don’t have your shell set up yet, do Q1 first (below)!)

  1. Go to your home directory (or wherever you wish to keep this homework directory):
  cd ~
  1. Clone the homework repository:
  git clone https://github.com/Missing-Semester-Berkeley/cs198-assignments.git
  1. cd into the homework repository to see the assignments:
  cd cs198-assignments

Feel free to post in Piazza if you run into any issues!

Required Questions

  1. For this course, you need to be using a Unix shell like Bash or ZSH. If you are on Linux or macOS, you don’t have to do anything special. If you are on Windows, you need to make sure you are not running cmd.exe or PowerShell; you can use Windows Subsystem for Linux or a Linux virtual machine to use Unix-style command-line tools. (You can follow 61A’s instructions to install Windows Subsystem for Linux here.To make sure you’re running an appropriate shell, you can try the command echo $SHELL. If it says something like /bin/bash or /usr/bin/zsh, that means you’re running the right program. There is nothing to be turned in for this problem.
  2. Our first built-in programs: man and touch:
    1. Look up the touch program. The man program is your friend.
    2. Use touch to create a new file called semester in hw00.
  3. Write the following into that file, semester one line at a time:
    #!/bin/sh
    curl --head --silent https://cs198.org/
    

    The first line might be tricky to get working. It’s helpful to know that # starts a comment in Bash, and ! has a special meaning even within double-quoted (") strings. Bash treats single-quoted strings (') differently: they will do the trick in this case. See the Bash quoting manual page for more information.

  4. Execution:
    1. Try to execute the file, i.e. type the path to the script (./semester) into your shell and press enter. Understand why it doesn’t work by consulting the output of ls (hint: look at the permission bits of the file).
    2. Run the command by explicitly starting the sh interpreter, and giving it the file semester as the first argument, i.e. sh semester. Why does this work, while ./semester didn’t?
    3. Look up the chmod program (e.g. use man chmod).
    4. Use chmod to make it possible to run the command ./semester rather than having to type sh semester. How does your shell know that the file is supposed to be interpreted using sh? See this page on the shebang line for more information.
  5. Piping: Use | and > to write the “last modified” date output by semester into a file called last-modified.txt in your hw00 directory. This should be in the format of last-modified: Sun, 09 Jan 2022 08:39:42 GMT (with possibly different dates).

Submit your work by uploading the files semester and last-modified.txt to the Gradescope assignment.

Optional Questions

  1. Write a command that reads out your laptop battery’s power level or your desktop machine’s CPU temperature from /sys. Note: if you’re a macOS user, your OS doesn’t have sysfs, so you can skip this exercise.