def unquote_shell_arg(arg):
#===============================================================================
    """
    Return an argument with quotes removed if present.
    """
    sarg = str(arg)
    if len(sarg) == 0:
        return sarg
    quote_char = sarg[-1]
    if quote_char not in ('"', "'"):
        return sarg
    # Deal with a starting quote that might not be at the beginning
    if sarg[0] == quote_char:
        return sarg[1:-1]
    pos = sarg.find(quote_char)
    if pos == len(sarg) - 1:
        # No first quote, don't know what else to do but return as is
        return sarg
    return sarg[:pos] + sarg[pos+1:-1]