Don't write out unset values.
Adjust first line matching to work under Windows.
Added test script to cover custom executable in shebang.