Bug in shlex??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • samslists@gmail.com

    Bug in shlex??

    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:
    \?foo

    (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'")
    ['\\?foo']
    >>>
    I think this is a bug? Or am I just misunderstandin g?

    Here is the relevant section of the Posix specification on shell
    parsing:
    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!
  • Gabriel Genellina

    #2
    Re: Bug in shlex??

    En Thu, 03 Apr 2008 19:20:59 -0300, samslists@gmail .com
    <samslists@gmai l.comescribió:
    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:
    \?foo
    >
    (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'")
    ['\\?foo']
    >>>>
    >
    I think this is a bug? Or am I just misunderstandin g?
    The result is a list containing a single string. The string contains 5
    characters: a single backslash, a question mark, three letters. The
    backslash is the escape character, as in '\n' (a single character,
    newline). A backslash by itself is represented (both by repr() and in
    string literals) by doubling it.

    If you print the value, you'll see a single \:

    print shlex.split("'\ ?foo'")[0]

    --
    Gabriel Genellina

    Comment

    • ockman@gmail.com

      #3
      Re: Bug in shlex??

      Gabriel...

      I feel foolish...(and wish I had the two hours back I spent on
      this). :)

      Thank you so much!

      The result is a list containing a single string. The string contains 5
      characters: a single backslash, a question mark, three letters. The
      backslash is the escape character, as in '\n' (a single character,
      newline). A backslash by itself is represented (both by repr() and in
      string literals) by doubling it.
      >
      If you print the value, you'll see a single \:
      >
      print shlex.split("'\ ?foo'")[0]
      >
      --
      Gabriel Genellina

      Comment

      Working...