Say that ten times fast! Doctypeify is a UNIX script I wrote to facilitate adding DOCTYPEs to web pages without them. This is especially useful if you wish for your site to be compliant with W3C standards.
Use of the script is very simple and can be done in one of two ways. In method one, you simply change your current directory to a directory with web pages you wish to update, then call doctypeify.
cd /www/projects doctypeify
Doctypeify also allows you to point it to a directory, so the second method would be:
doctypeify /www/projects
As it is currently, doctypeify will not recursively check directories inside the one specified, so if you wish to do that then you simply need to call it again.
Currently, doctypeify will search for *.sHTML files and will update files missing a DOCTYPE with HTML 4.01 Transitional. This can be easily changed to suit your needs.
$ doctypeify writing Fixing writing/fair_weather_friends.shtml ... Fixing writing/grade_school.shtml ... Fixing writing/oops.shtml ... Fixing writing/writing_projects.shtml ... The following documents were given DOCTYPEs: writing/fair_weather_friends.shtml writing/grade_school.shtml writing/oops.shtml writing/writing_projects.shtml
#! /bin/sh # This script is designed to peer into the provided directory # and check shtml files for DOCTYPES. If a .shtml file is # found without a DOCTYPE, then one will be added. # (C)2005 Nic Reveles # First, make sure we have a valid use of doctypeify if [ $# -gt 1 ]; then echo "Improper use: doctypeify /some/HTML/directory" exit 0 fi if [ $# -eq 0 ]; then dir=`pwd` else dir=$1 fi # Save any files that already have doctypes in a temporary file grep -H "DOCTYPE HTML PUBLIC" $dir/*.shtml > $HOME/.temp_doctype cut -d : -f 1 $HOME/.temp_doctype > $HOME/.temp_doctype2 # Save _ALL_ applicable files in another temp file ls $dir/*.shtml > $HOME/.temp_doctype # Now get any file which does _not_ have a DOCTYPE diff -b $HOME/.temp_doctype $HOME/.temp_doctype2 > $HOME/.temp_doctype3 # If there are no files to be fixed, be done if [ $? -eq 0 ]; then echo "All *.shtml files were correct" rm $HOME/.temp_doctype $HOME/.temp_doctype2 $HOME/.temp_doctype3 exit 0 fi # Now save the doctype itself to a temp file echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN' >> $HOME/.temp_doctype echo '"http://www.w3.org/TR/html4/loose.dtd">' >> $HOME/.temp_doctype echo "" >> $HOME/.temp_doctype # Remove garbage from 'diff' command cut -s -d '<' -f 2 $HOME/.temp_doctype3 > $HOME/.temp_doctype2 # loop through all *.shml files missing command and append that to the beginning for badfile in `cat $HOME/.temp_doctype2` do echo "Fixing $badfile ..." cat $HOME/.temp_doctype > $HOME/.temp_doctype3 cat $badfile >> $HOME/.temp_doctype3 cat $HOME/.temp_doctype3 > $badfile done echo "" echo "The following documents were given DOCTYPEs:" cat $HOME/.temp_doctype2 #finally, clean up after ourselves... rm $HOME/.temp_doctype $HOME/.temp_doctype2 $HOME/.temp_doctype3
(c) 2005 Nic Reveles
Updated