import shlex tokens = ["echo", "-n", "Python is awesome"] shlex.join(tokens) # "echo -n 'Python is awesome'"