Support platforms that don't have environ in any header (e.g. FreeBSD)
Use /bin/sh rather than /bin/bash for more portability.  The scripts
aren't using anything other than POSIX shell syntax anyway.
Set the open flags correctly for the output:
- We only write so O_WRONLY is more appropriate.
- We should set O_TRUNC because otherwise you end up producing a
  corrupted file if the new output is shorter.