Parsing a bash string?

From: seguso (look_at_in.signature)
Date: 09/18/04

  • Next message: John L: "Re: Parsing a bash string?"
    Date: Sat, 18 Sep 2004 09:30:55 GMT
    
    

    Hello,

    For my application (http://onefinger.sf.net), which is a wrapper over bash,
    I have to be able to parse a command line typed by the user.

    I.e., I need a function that, when given a typical bash command string like

    mplayer -sub /usr/a\ good\ movie.srt "/home/a good movie.avi"

    , outputs a list of python strings (tokens):

    [ "mplayer", "-sub", "a good movie.srt", "/home/a good movie.avi"]

    Writing this function doesn't seem easy to me: it seems I must split the
    string when I encounter a space/tab, but not if the space/tab is enclosed
    into quotes... furthermore, I have to remove the quotes (notice the last
    token in the string has the quotes removed).

    Do you know some python library I can use? Or is there an easier way?

    PS: The current implementation is broken when the user writes quotes.

    Thanks for any help,

    -- 
    Best Regards,
    Maurizio Colucci --- http://onefinger.sf.net
    Please remove the uppercase letters "S,P,A,M":
    seSgPuAsMo.forever@tin.it
    

  • Next message: John L: "Re: Parsing a bash string?"

    Relevant Pages

    • Re: Get Selected Path From Explorer
      ... Getting a file string from Explorer from VB using the Command line ... In this instance stripping the quotes from the beginning and end of the ... strExplorerPath = Left$- 1) ...
      (microsoft.public.vb.general.discussion)
    • Re: runas: need help with those quotes
      ... matters, both paths have spaces, so they are enclosed in quotes. ... 'This command echos the the strCmd to the screen. ... Quotes embedded in a quoted string should be doubled. ...
      (microsoft.public.scripting.vbscript)
    • Re: runas: need help with those quotes
      ... matters, both paths have spaces, so they are enclosed in quotes. ... 'This command echos the the strCmd to the screen. ... Quotes embedded in a quoted string should be doubled. ...
      (microsoft.public.scripting.vbscript)
    • Re: XP SP2 command line trouble - update
      ... If the OS is wrapping the path in quotes ... de-quote the strings, which would just need a function you pass any string ... unquote = replace$, "") ... command line itself, on at least this particular XP SP2 ...
      (microsoft.public.vb.general.discussion)
    • Re: Yet another "stop the bash quoting" post
      ... > Output from running the file1.sh command is: ... > that 'command' gets from the shell contains those single quotes too. ... By using set -x in the bash script and running /command/ without the ... not recognizing either as a switch, probably because they start with a ...
      (comp.os.linux.misc)