def argv2line(argv):
    """Put together the given argument vector into a command line.

        "argv" is the argument vector to process.

    >>> from listcmd import argv2line
    >>> argv2line(['foo'])
    'foo'
    >>> argv2line(['foo', 'bar'])
    'foo bar'
    >>> argv2line(['foo', 'bar baz'])
    'foo "bar baz"'
    >>> argv2line(['foo"bar'])
    'foo"bar'
    >>> print argv2line(['foo" bar'])
    'foo" bar'
    >>> print argv2line(["foo' bar"])
    "foo' bar"
    >>> argv2line(["foo'bar"])
    "foo'bar"
    """
    escapedArgs = []
    for arg in argv:
        if ' ' in arg and '"' not in arg:
            arg = '"' + arg + '"'
        elif ' ' in arg and "'" not in arg:
            arg = "'" + arg + "'"
        elif ' ' in arg:
            arg = arg.replace('"', '\\"')
            arg = '"' + arg + '"'
        escapedArgs.append(arg)
    return ' '.join(escapedArgs)
