def bash_quote(s):
    """
    POSIX-compatible argument escape function designed for bash. Use this to quote variable
    arguments that you send to `container.bash("...")`.

    Note that pipes.quote and subprocess.list2cmdline both produce the INCORRECT value to use in
    this scenario. Do not use those. Use this.

    Example:

        container.bash("ls -ahl %s" % bash_quote(file_name))

    """

    return "'" + s.replace("'", "'\\''") + "'"