from typing import Dict
from typing import Optional


def make_env_shell_str(env: Dict[str, str]) -> Optional[str]:
    """
    Transforms env dict to string suitable for use in shell
    Returns None for empty dict
    """
    env = env or {}

    result = []
    for k, v in env.items():
        value = v
        if "$" in v or " " in v:
            q = '"'
            if q in v:
                q = "'"
            value = f"{q}{v}{q}"

        result.append(f"{k}={value}")

    return " ".join(result) or None