Consider: >>> import shlex >>> shlex.split('$(which sh)') ['$(which', 'sh)'] Is this behavior correct? It seems that I should either get one token, or the list ['$','(','which','sh',')'], but certainly breaking it the way it does is erroneous. Can anyone explain why the string is being split that way?