def substitute_variables(cmd, variables):
    """Given a cmd (str, list), substitute variables in it."""
    if isinstance(cmd, list):
        return [s.format(**variables) for s in cmd]
    elif isinstance(cmd, str):
        return cmd.format(**variables)
    else:
        raise ValueError(f"cmd: {cmd}: wrong type")