Due: Monday, January 24, at 11:00pm
In this assignment you'll gain some more experience with shell commands and with writing short shell scripts.
General hint: Before trying to write and debug a script, it's very helpful to first work out the necessary commands by experimenting in a shell window. Similarly, you can test one statement in your script at a time in your shell. Also, look at man pages and other descriptions of commands. Sometimes options are available that allow a single command to do something you want instead of having to use several commands or writing loops or complex control structures in a script. You can also find ways to control how much output a command gives.
combine
that takes 2
or more arguments, call them f1, f2, ...,
fn
.combine
should work as follows:Usage: combine outputfilename [inputfilename ...]
error message on stderr
and exit
with a return code of 1.f1
already exists, print
Error: Output file should not exist
on stderr
and
exit with a return code of 1.f2, ...,
fn
and put them in f1
. You will want to handle errors with input files, but do not print
any error messages from this (for example if some file does
not exist or is a directory). Instead, these error messages
should be written to f1
. Exit
with a return code of 0 after copying the intput files.
[localhost]$ echo "making file 1" > file1 [localhost]$ echo "and another one for file 2" > file2 [localhost]$ touch file3 [localhost]$ ./combine output file1 file2 nonfile file3 [localhost]$ cat output making file 1 and another one for file 2 cat: nonfile: No such file or directory
/dev/stdout
or /dev/stderr
. These are not portable across *nix
systems. Although they are found on most versions of Linux the
problem can be solved without them.cat, shift, $@, -lt, -a
.spellcheck
spellcheck
should work as follows:
stderr
and exit with a code of 1 [ ! -f $1 ]
), spellcheck prints an appropriate error message to stderr
and skips that argument.
grep
to compare that word to the dictionary (which is assumed to exist at /usr/share/dict/words
). If the word is not found in the dictionary it should be added to the end of a file called <FILE>.spelling
.* You may add repeated words to the word list in the initial step.<FILE>.spelling
does not exist, print a message to stdout stating that the script is creating it.<FILE>.spelling
already exists, print a message to stdout stating that you are deleting the old file and replacing it../spellcheck longtext
will create a file called longtext.spelling
, which contains a list of words such a 'gnu.org' and 'Korn'. Example output is here:$ ./spellcheck shorttext ./spellcheck creating shorttext.spelling file ./spellcheck processed shorttext and found 1 spelling errors 1 of which are unique $ ./spellcheck tricky shorttext ./spellcheck error: tricky does not exist - skipping. ./spellcheck replacing shorttext.spelling file ./spellcheck processed shorttext and found 1 spelling errors 1 of which are unique.Hints:
longtext
file has 9 spelling errors 8 of which are unique.wget https://courses.cs.washington.edu/courses/cse374/22wi/assignments/FILENAME
combine
script should provide a method for stepping through input arguments that you can re-use here.grep
to find words in a file. Look for options that allow case insensitive and quiet operation.bash
on either of our
reference systems (cancun
or the current CSE Linux virtual
machine).Please submit your files to Gradescope, which can be reached through Canvas or directly. You will submit two files, called combine and spellcheck.
There will be an autograder for these assignments, with additional manual checking for a few points. Students may re-submit to improve their scores through the initial due date. (The manually graded questions will not be evaluated until there is a perfect score on the autograded portion, OR, the initial due date is past.)