def sys_print_commands(
    variables, dump_rate, filename, fix_name="sys_info", append=True, print_header=True
):
    """Create commands to output required system variables to a file."""
    commands = []

    if not variables:
        return commands

    if "step" not in variables:
        # always include 'step', so we can sync with the `dump` data
        variables.insert(0, "step")

    var_aliases = []
    for var in variables:
        var_alias = var.replace("[", "_").replace("]", "_")
        var_aliases.append(var_alias)
        commands.append("variable {0} equal {1}".format(var_alias, var))

    commands.append(
        'fix {0} all print {1} "{2}" {3} {4} {5} screen no'.format(
            fix_name,
            dump_rate,
            " ".join(["${{{0}}}".format(v) for v in var_aliases]),
            'title "{}"'.format(" ".join(var_aliases)) if print_header else "",
            "append" if append else "file",
            filename,
        )
    )

    return commands