See https://github.com/ged-lab/khmer/blob/bleeding-edge/sandbox/write-trimmomatic.py for the script source.

Yeah, I struggled with this for a while.  It seemed easier to write it in Python... but that was before I invested in all the other shell stuff below.  Sigh.