back to eggert home
back to home

assign 1

welcome to to hell that is 35l.
this first assignment has you do things with emacs and bash, so we're off to a great start
i'm gonna assume you took 31 or 32 and have one of those seasnet accounts to login with

setup

  1. ssh into `lnxsrv11`, `lnxsrv13`, or `lnxsrv15` with this command: ```bash ssh [username]@lnxsrv11.seas.ucla.edu # replace 11 with another if you wanna ``` vsc also has ssh support if you're that kinda person
  2. go to the filepath `~/.profile` or create one if it doesn't already exist and add this text: ```bash export PATH=/usr/local/cs/bin:$PATH ``` `/usr/local/cs/bin` has some cool commands and stuff that the course uses
    pretty sure you have to log out and log back in again as well

some scavenger hunt lab

lab 1.0

nothing much, just first make sure emacs is doing its thing by typing ```bash emacs --version ``` it should be 29.1

then actually start it up by running emacs without that version flag
start the tutorial by pressing `Ctrl+h` and `t`- notice that you have to do two sets of keypresses!
disclaimer: you don't have to go through all of it, just enough to give you a general idea of how crap works

lab 1.1

run this command: ```bash wget2 https://web.cs.ucla.edu/classes/winter24/cs35L/assign/assign1.html ``` this downloads a copy of winter 24's assignment 1 webpage to your file system
change the quarter to yours i suppose

next, copy the file (it should be DL'ed as `assign1.html`) to 3 new names: `exer1.html`, `exer2.html`, and `exer3.html`
you can do this with the `cp` command like so: ```bash cp assign1.html exer1.html # and ditto for exer2/exer3 ``` we'll mess around with the other 2 files later, but first open `exer1.html` with this command: ```bash emacs exer1.html # or whatever path you've copied it to ```

run the emacs command `M-x open-dribble-file` to create a dribble file `lab1.drib` that will log all your keypresses for the current session
later, you'll do the same for labs 1.2, 1.3, and 1.4- make `lab[x].drib` files for those as well

perform the following actions with cool emacs commands- don't just use the arrow keys for everything

  1. use searching to move the cursor to just after the first occurrence of the string "UTF-8" (all upper-case).
  2. now move the cursor to the start of the first later occurrence of the word "scavenger".
  3. now move the cursor to the start of the first later occurrence of the word "self-referential".
  4. now move the cursor to the start of the first later occurrence of the word "arrow".
  5. now move the cursor to the end of the current line.
  6. now move the cursor to the beginning of the current line.
  7. that's it! do `C-x C-c` to exit emacs and you should see all your keypresses in `lab1.drib`

the TAs won't like check if you've done the actions exactly- they'll just check if the commands you used are efficient enough, like using `C-s` for forward searching and `C-a` for going to the beginning of a line

lab 1.2

open emacs on `exer2.html` this time and create the appropriate dribble file

do these tasks, which should eventually remove all html comments on the page
again, be sure to use cool emacs commands instead of backspacing everything

  1. delete the 71st line, which should be smth like this: ```html <!-- HTML comments look like this, but the comment you delete has different text inside. --> ```
  2. delete the comment containing the text `DELETE-ME DELETE-ME DELETE-ME`
  3. ditto, but w/ the comment containg `https://en.wikipedia.org/wiki/HTML_comment#Comments`
  4. should be 2 more comments in the page- kill those asw
  5. alr you're done, exit emacs

to check your work, run this command: ```bash diff -u exer1.html exer2.html >exer2.diff ``` it should contain only the text you wanna remove, smth like this: ```diff --- exer1.html 2024-03-26 08:11:17.370737753 -0700 +++ exer2.html 2024-03-26 08:11:17.370737753 -0700 @@ -68,7 +68,6 @@ and you are not expected to read it all.</li> </ul> -<!-- diff,在UNIX系統上的一個工具程式,它可以比較兩個檔案之間的不同。通常它被用來比較同一個檔案,在不同版本間的差異。它可以產生一個擴展名為.diff或.patch的檔案,這個檔案可以被另一個工具程式patch來使用。--> </section> <section> ``` don't stress if your file doesn't match this exactly- again, the TAs just look to see which commands you used for deletion or whatever

lab 1.3

open emacs on `exer3.html`, yada yada

  1. change the first two instances of `Assignment 1` to `Assignment 27`
  2. change the first instance of `UTF-8` to `US-ASCII`.
  3. alright now that we've said that our file is ascii, we should probably make it that way
    most of the chars are the unicode character here -> ’; fix these by replacing each one with a normal ascii apostrophe- `'`
    psst, `M-x replace-string` is pretty cool
  4. find the first remaining non-ascii char
    you can do this by searching for the regex `[^[:ascii:]]`.
  5. what is that char? you can use `C-u C-x = (what-cursor-position)` to find out
    put the answer in a file named `notes.txt`
  6. remove every line that contains a non-ascii character, besides the apostrophe chars you alr replaced
  7. kk exit emacs now- if you wanna, use `diff` to check your output or whatever

lab 1.4

this one actually doesn't start with opening an exer file, wow!

  1. run this: ```bash # creates exer4.html, which consists of # a copy of exer2.html followed by a copy of exer2.diff cat exer2.html exer2.diff >exer4.html ``` we're gonna try to modify `exer4.html` so that it looks like `exer1.html`, just with some extra stuff at the end
  2. oh- now open `exer4.html` and do the whole dribble file thing
  3. go to the end of the file and copy the new lines in the last chunk of diff output
  4. paste them into the correct location in the html part of the file
  5. repeat for all the chunks of the output
  6. delete the diff output from `exer2.diff`
  7. undo that deletion (wtf??)
  8. turn the diff output into a comment by surrounding it with `<!--` and `-->`
    if the diff output itself contains end-comment markers `-->`, escape them by replacing each such `-->` w/ `--&gt;`.
  9. search the doc for `<ol>`- how many did you find? put the answer in `notes.txt`
  10. replace all of em w/ `<oL>` cuz why not

check by running the shell command `diff -u exer1.html exer4.html`
the only differences should be changes from `<ol>` to `<oL>` and a giant html comment at the end
but don't stress if your output is ever so slightly different! again, the TAs will just look if you used cool emacs commands

lab 1.5

put all the answers here along with the commands you used to get them in `notes.txt`
most of the questions here are suffixed by a cool command that can be used for it because there's no goddamn way people are supposed to figure this out by themselves

  1. where are the `sh`, `sleep`, and `type` commands located? - `which`
  2. what executables in `/usr/bin` have names that are exactly three characters long and start with the two letters `se`, and what do they do? - `grep`, `man`
  3. when you run the symbolic link (symlink for short) `/usr/local/cs/bin/emacs`, which file actually is run? - `readlink`
  4. what's is the version number of `/usr/bin/gcc`? what about `gcc`? why are the two different? - `gcc` (obv), `type`
  5. the `chmod` program changes permissions on a file. what does the symbolic mode `u+sx,o-w` mean, in terms of permissions? - `man`
  6. use `find` to find all directories that are located under (or are the same as) the directory `/usr/local/cs`, and that were modified after the directory `/usr/local/cs/lib` was modified. sort them alphabetically and list the first five names - `find`
    be sure to type out the FULL, ABSOLUTE PATHS- NO `.` OR `..` OR WHATEVER
  7. how many regular files match the pattern `/usr/local/cs/src/python/Python-*`? we're just talking about regular files here, no symlinks, directories, or any fancy crap - `find`, `wc`
  8. how many files in `/usr/local/cs/bin` are symlinks? - `find`, `wc`
  9. what's the oldest file in the `/usr/lib64` directory? use the last-modified time to determine age - `find`, `sort`
    there's a bunch of conditions for this problem
  10. in emacs, what commands have `transpose` in their name? - `C-h a`
  11. what does the emacs `yank` function do, and how can you easily invoke it using keystrokes? - `C-h f`
  12. use `ps` to find your own login shell’s process, all that process’s ancestors, and all its descendants
    some cool options are `-e`, `-f`, `-j`, `-l`, `-t`, `-H`, and `-T`

lab 1.6

the spec says to do this in emacs, but it doesn't matter
the TAs literally don't check if you did it so

create this file named `hello.c` or whatever you want with the following content: ```c #include <stdio.h> int main (void) { for (;;) { int c = getchar (); if (c < 0) { if (ferror (stdin)) perror ("stdin"); else fprintf (stderr, "EOF on input\n"); return 1; } if (putchar (c) < 0 || (c == '\n' && fclose (stdout) != 0)) { perror ("stdout"); return 1; } if (c == '\n') return 0; } } ```

  1. compile it, either in emacs w/ `M-x compile` or gcc w/ `gcc hello.c`
  2. run it, either in emacs w/ `M-!` or in bash w/ `./a.out`
    put the program’s standard output (stdout) into a file named `hello-a1` and its standard error (stderr) into a file `hello-a2`
  3. same as before, except run the program with stdin closed, and put stdout/stderr into `hello-b1` and `hello-b2` respectively.
    note that closing standard input isn't the same as having an empty input file!
    you can arrange for this via the `<&-` shell syntax
    by that, eggert means you can do this: ```bash ./a.out <&- # output redirection omitted ```
  4. now run the program with stdin being the file `/etc/passwd`, and redirect stdout/stderr to `hello-c1`/`hello-c2`
  5. ok try doing it with stdin being the file `/etc/passwd` and stdout being the file `/dev/full`; put stderr into `hello-d2`

actual bash scripting

intro

i really recommend you understand these commands first before doing this assignment
if you don't, you can use `man` or `tldr` to figure that out

  1. `cat`
  2. `tr`
  3. `sort`
  4. `comm`
  5. oh yeah also make sure you get piping and whatnot

startup

use the `sort` command and some funny redirection to make a file named `sorted.words` that contains all the words of `/usr/share/dict/linux.words` in alphabetical order

now, take this lil bash script: ```bash tr -cs 'A-Za-z' '[\n*]' | sort -u | comm -23 - sorted.words ``` it tries to be a rudimentary spellchecker, but it kinda sucks

to see why, run this command, which runs the script with the very dictionary we generated `sorted.words` from: ```bash tr -cs 'A-Za-z' '[\n*]' </usr/share/dict/linux.words | sort -u | comm -23 - sorted.words ``` a bunch of weird words come out! try to figure out why first before moving on

the actual task

write a shellscript named `myspell` that looks at `linux.words` and spellchecks some text given from stdin
by that, i mean it should take in text from stdin and output misspelled words to stdout

for this assignment, a "word" can be defined as just any consecutive string of uppercase or lowercase alphabets
so don't worry, the given `tr` command: ```bash tr -cs 'A-Za-z' '[\n*]' ``` will work just fine for separating out all the "words" of a file

if you want to, you can make a helper script `makedict` to preprocess `linux.words` first
but beware- the TAs won't call it for you! you have to run it yourself in `myspell`

you can expect the TAs to call it like so: ```bash ./myspell <file_with_words_idk.txt ```

sanity checks

```bash ./myspell </usr/share/dict/linux.words ``` should output nothing because the dictionary by definition should only contain correctly spelled words

say we have the following file named `lol.txt`: ``` I love Software Construction I love software Construction? Professor Eggert is the best I am "enjoying" the class Am_I_enjoying_the_class? we-all love sushi. whitefish-taste-bad ``` when we run the following command: ```bash ./myspell <lol.txt >output.xt ``` a new file `output.txt` should appear with the following text: ``` Construction Eggert Professor Software ```

if the TAs say the output should be otherwise, believe them!

what to turn in

alright i won't be ambiguous, here's a list of all files that should be in your thing

submit these files as a `.tgz` file- you can generate this by doing the following command: ```bash tar -cvzf assign1.tgz lab1.drib lab2.drib # .. i'm not gonna list all the files here ``` you can check that all the files are in there by doing this: ```bash tar -tvf assign1.tgz ```