def shell_split(text):
 assert is_text_string(text)
 pattern = '(\\s+|(?<!\\\\)".*?(?<!\\\\)"|(?<!\\\\)\\\'.*?(?<!\\\\)\\\')'
 out = []
 for token in re.split(pattern, text):
  if token.strip():
   out.append(token.strip('"').strip("'"))
 return out

def shell_split ( text ) : assert is_text_string ( text ) pattern = '(\\s+|(?<!\\\\)".*?(?<!\\\\)"|(?<!\\\\)\\\'.*?(?<!\\\\)\\\')' out = [ ] for token in re . split ( pattern , text ) : if token . strip ( ) : out . append ( token . strip ( '"' ) . strip ( "'" ) ) return out
split the string text using shell-like syntax this avoids breaking single/double-quoted strings .