def append_footer(cmd, marker):
    """
    Append header/footer to `cmd`.

    Returns:
        str: new_command
    """
    header = ""
    footer = """
EXIT_CODE=$?
echo {marker}code: ${{EXIT_CODE}}{marker}
echo {marker}pwd: $(pwd){marker}
echo {marker}env: $(cat -v <(env -0)){marker}
""".format(
        marker=marker
    )

    full_command = "\n".join([header, cmd, footer])

    return full_command