shlex does not handle ANSI-C Quoting properly. Words of the form
    $'string' are treated specially. The word expands to string, with
    backslash-escaped characters replaced as specified by the ANSI C
    standard. This is a hacky workaround to parse these the way we want to.

def ansi_c_quoting(s):
    '''shlex does not handle ANSI-C Quoting properly. Words of the form
    $'string' are treated specially. The word expands to string, with
    backslash-escaped characters replaced as specified by the ANSI C
    standard. This is a hacky workaround to parse these the way we want to.'''
    in_single_quotes = False
    in_double_quotes = False
    maybe_ansi_c_quote = False
    in_ansi_c_quote = False
    to_del = []
    s = list(s)

    for index, ch in enumerate(s):
        if ch == '\'':
            if in_ansi_c_quote:
                in_ansi_c_quote = toggle(in_ansi_c_quote)
                s[index] = '"'
            else:
                in_single_quotes = toggle(in_single_quotes)
        if ch == '"':
            if in_ansi_c_quote:
                s[index] = '\\"'
            else:
                in_double_quotes = toggle(in_double_quotes)
        if ch == '$' and not in_single_quotes and not in_double_quotes:
            maybe_ansi_c_quote = True
        if maybe_ansi_c_quote and ch == '\'':
            maybe_ansi_c_quote = False
            in_ansi_c_quote = True
            s[index] = '"'
            to_del.append(index-1)
        if in_ansi_c_quote and ch in '\a\b\f\n\r\t\v':
            s[index] = repr(ch)[1:-1]
    to_del.reverse()
    for i in to_del:
        del s[i]
    return ''.join(s)