This very simple program has proven pretty useful. It just copies stdin to stout looking for lines that start with a hash bang (#!). When it finds one, that line is replaced by the stdout of the rest of the line as a command. Below are three versions.
#!/usr/bin/perl # This just copies stdin to sdtout # replacing all lines that start with #! # with the results of the command on that line. # This is good for templates. while ( <> ) { if ( /^#!/ ) { system( $' ); } else { print; } }
#!/usr/bin/ruby ARGF.each { |theLine| if ( m = /^#!/.match theLine ) system m.post_match else puts theLine end }
#!/bin/bash while read line do command=${line###!} if [ "$command" = "$line" ] then echo $line else $command fi done
Look at the Makefile in this directory to see one way it can be used to generate ubercat.html. We export some shell variables that are used within ubercat.html.uc. This way all the file names appear in the Makefile and none are hidden in ubercat.html.uc. Note that the Bash version cannot be used this way. It doesn't expand the shell variables in ubercat.html.uc.
When combined with something like tag.awk this can give us a poor man's HTML decorator. Look in the Makefile for how index.html is made.
See also Decorate XML. It is specialized to be friendlier to web designers. Note that the hash-bang commands for ubercat will break conformance with xml and possibly other standards.