factor out escape_for_bash to a header file

This way the escaping function can be called from other programs, e.g.,
echo-and-run.