def METHOD_NAME(cls, command):
    replacements = [
        # escape ! as \!
        ('!', "\\!"),
        # see Shell.join()
        ('"', '"\'"\'"'),
        # similar to above, but for backticks
        ('`', '"\'`\'"'),
        # escape $ if not part of a valid var ref like $FOO, ${FOO}
        (re.compile(r"\$([^a-zA-Z{])"), '"\'$\'"\\1'),
        (re.compile(r"\$$"), '"\'$\'"')  # edge case, $ at end
    ]
    return shlex_join(command, replacements=replacements)