shlex.split()
shlex.split() is a Python function in the Shlex Module category. Splits a shell-like string into tokens, respecting quotes. The syntax is shlex.split(s, comments=False, posix=True). Parameters: s — shell command string. Returns: List of tokens. A typical example: import shlex
shlex.split("echo 'hello world'") # ["echo", "hello world"]
shlex.split("cmd --name=\"John Doe\"") # ["cmd", "--name=John Doe"]. A close sibling is shlex.join(), which joins tokens into a shell-safe command string. A close sibling is shlex.shlex(), which creates a lexical analyzer for shell-like syntax. More about this category: Shell lexical analyzer — shlex, split, join. Related Shlex Module entries: shlex.join(), shlex.shlex(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try shlex.split() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.