import typing
import shlex


def cmd_to_string(command: typing.Union[str, typing.Iterable[str]]) -> str:
    """Convert command to string for usage with shell.

    :param command: original command.
    :type command: typing.Union[str, typing.Iterable[str]]
    :return: command as single string
    :rtype: str
    """
    if isinstance(command, str):
        return command
    return " ".join(shlex.quote(elem) for elem in command)