Name:
PID: (page 1)
bash-3.2$ wc /usr/share/dict/words
235976 235976 2493885 /usr/share/dict/words
bash-3.2$ head -n 10 /usr/share/dict/words
A
a
aa
aal
aalii
aam
Aani
aardvark
aardwolf
Aaron
bash-3.2$ tail -n 10 /usr/share/dict/words
zymotoxic
zymurgy
Zyrenian
Zyrian
Zyryan
zythem
Zythia
zythum
Zyzomys
Zyzzogeton
What about getting all the file extensions in use across the whole project?
What about counting the number of lines/characters *by file extension*? (e.g. how many lines of .ts code, how many lines of .tsx code)
Another useful resource (if we have time) – there’s a dictionary installed in a plain text file on most operating systems. Anything interesting we can do with it?
xargs «command» perform «command» after reading standard input to get all the command-line arguments
«command» | «command» “pipe” – Take the output of the first command and use it as the input to the second command.
Any other ways to write the example above with | and xargs?
Name:
PID: (page 2)
class CompileError {
public static void main(String[] args) {
int x = "not-a-number";
}
}
CompileError.java
$ javac CompileError.java >error-output.txt
CompileError.java:3: error: incompatible types:
String cannot be converted to int
int x = "not-a-number";
^
1 error
$ cat error-output.txt # nothing in this file!
$ javac CompileError.java ________________________________
$ cat error-output.txt
CompileError.java:3: error: incompatible types:
String cannot be converted to int
int x = "not-a-number";
^
1 error
class PrintThenThrow {
public static void main(String[] args) {
System.out.println("Hello!");
System.err.println("Error!");
throw new RuntimeException("This is an error!");
}
}
PrintThenThrow.java
$ java PrintThenTrow >out.txt
Error!
Exception in thread "main" java.lang.RuntimeException: This is an error!
at PrintThenTrow.main(PrintThenThrow.java:4)
$ cat out.txt
_________________________________
$ java PrintThenTrow >out.txt 2>&1
$ cat out.txt
Hello!
Error!
Exception in thread "main" java.lang.RuntimeException: This is an error!
at PrintThenTrow.main(PrintThenThrow.java:4)
Processes actually have two different default places to print: standard output and standard error
Programming languages typically have a way to select one or the other when printing. In Java, there's System.err.print
Many programs, when they report an error message, print to standard error (also called stderr).
We can observe this difference with redirection: cmd 2>file.txt redirects the output of the command's stderr to file.txt
cmd >file.txt 2>&1 redirects stderr to stdout and then both to file.txt
Brainstorm: What makes a good autograder script? How might it work?
Hint – imagine this setup. Gradescope runs:
$ bash grade.sh <student-github-url>
and whatever the text output of that command is gets sent back to the student. What are the steps to, say, grade a PA.
Imagine students submitted their DocSearchServer that we used in lab that searches files, for example. What should the grader do?