Due: Tue, Dec 13, 7:00am
In this project, you will implement a shell script called htmlper.sh that helps with writing HTML files. HTML is the markup language of webpages. When your browser fetches a webpage, the browser is really downloading HTML files (as well as other assets like JaveScript and style sheets), and then rendering these files to your screen. Like many shell scripts, htmlper.sh wraps and composes a few existing programs to provide a convenient interface.
./htmlper.sh index.html
creates a file called index.html with the following content:
If the file index.html already exists, then htmlper.sh prompts the user whether to overwrite the file or quit.
If the -t TITLE option is also given, then htmlpers.h sets the title tag's inner text to TITLE as part of creating the new file. For instance, the command:
./htmlper.sh -t Trees index.html
creates a file called index.html with the contents:
Otherwise, exactly one of the -p (prettify), -s (spell-check), or -v (validate) options is provided, with htmlper.sh performing that operation on an existing HTML_FILE.
Print a usage statement to stdout and exit with status 0.
Remove trailing white space (spaces and tabs) from all lines in HTML_FILE.
Spell check HTML_FILE using the aspell utility. The output is an alphabetically ordered list of misspellings prefaced with the number of times that the misspelling occurred.
Set the title tag's inner text to TITLE. This option is used only in conjunction with the default operation of generating a new HTML file.
Validate that HTML_FILE is a properly formatted HTML file using the tidy utility. If HTML_FILE is properly formatted, htmlper.sh prints the line $HTML_FILE passed validation to stdout; otherwise, htmlper.sh prints the line $HTML_FILE failed validation to stdout, and then prints a list of the file's syntactical errors/warnings.
Submit your project as a zip file via gradescope. The zip file should contain a single executable file called htmlper.sh. Please refer to the instructions for submitting an assignment for details on how to login to gradescope and properly zip your project.
./htmlper.sh -h
Prints a usage statement to stdout. The statement must start with either Usage or usage; you decide the rest of the message. Conventionally, this option either prints the synopsis or a more verbose statement that also includes a description of the options.
./htmlper.sh -h
echo $?
0
The exit status is zero.
./htmlper.sh -v -s index.html
Prints a one line message to stderr.
./htmlper.sh -v -s index.html
Specifying multiple operations causes htmlper.sh to terminate with a nonzero exit status.
./htmlper.sh index.html
Creates a new file index.html.
./htmlper.sh -t Trees trees.html
Creates a new file trees.html.
./htmlper.sh overwrite.html.
overwrite.html already exists. OK to overwrite? [y/n]: y
Assuming overwrite.html already exists, htmlper.sh queries the user whether to overwrite the file. The user enters y, and the script overwrites the file. The byte-for-byte content of htmlper.sh should now be the same as index.html.
You can change the message that htmlper.sh presents to the user, but your script must handle the responses of y or n.
./htmlper.sh overwrite.html.
overwrite.html already exists. OK to overwrite? [y/n]: n
Assuming overwrite.html already exists, htmlper.sh queries the user whether to overwrite the file. The user enters n, and the script terminates and does not overwrite the file. In particular, overwrite.html should still have the same content.
You can change the message that htmlper.sh presents to the user, but your script must handle the responses of y or n.
./htmlper.sh -p index-trailing-spaces.html
After execution, index-trailing-spaces.html should have the same byte-for-byte content as index.html.
./htmlper.sh -p index-trailing-spaces-tabs.html
After execution, index-trailing-spaces-and-tabs.html should have the same byte-for-byte content as index.html.
./htmlper.sh -s mispellings.html
1 blu
1 lullabie
2 rainbox
2 teh
Prints the above output to stduot. The amount of whitespace that you use when formatting each line of output is irrelevant.
./htmlper.sh -v index.html
index.html passed validation
Prints the above output to stdout.
./htmlper.sh -v invalid.html
invalid.html failed validation
line 9 column 5 - Warning: missing </h1> before </h2>
line 9 column 22 - Warning: discarding unexpected </h2>
Prints the above output to stdout. To tolerate potential differences in output between different versions of tidy, the test only checks that the script wrote two or more lines to stdout, with the first line exactly matching invalid.html failed validation.