Bug in shlex??

samslists at gmail.com samslists at gmail.com
Fri Apr 4 00:20:59 CEST 2008

I'm trying to use shlex.split to simulate what would happen in the
shell.  The docs say that it should be as close as possible to the
posix shell parsing rules.

If you type the following into a posix compliant shell

echo '\?foo'

you get back:

(I've tested this in dash, bash and zsh---all give the same results.)

Now here's what happens in python:

Python 2.5.1 (r251:54863, Mar  7 2008, 03:39:23)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shlex
>>> shlex.split("'\?foo'")

I think this is a bug?  Or am I just misunderstanding?

Here is the relevant section of the Posix specification on shell
   2.2.2 Single-Quotes

   Enclosing characters in single-quotes ( '' ) shall preserve the
literal value of each character within the single-quotes. A single-
quote cannot occur within single-quotes.

That's from

Thanks for any help!

More information about the Python-list mailing list