Parsing a bash string?
From: seguso (look_at_in.signature)
Date: 09/18/04
- Previous message: P.T. Breuer: "Re: Switching from tcsh to bash as an interactive shell"
- Next in thread: John L: "Re: Parsing a bash string?"
- Reply: John L: "Re: Parsing a bash string?"
- Reply: William Park: "Re: Parsing a bash string?"
- Reply: rakesh sharma: "Re: Parsing a bash string?"
- Reply: Stephane CHAZELAS: "Re: Parsing a bash string?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: P.T. Breuer: "Re: Switching from tcsh to bash as an interactive shell"
- Next in thread: John L: "Re: Parsing a bash string?"
- Reply: John L: "Re: Parsing a bash string?"
- Reply: William Park: "Re: Parsing a bash string?"
- Reply: rakesh sharma: "Re: Parsing a bash string?"
- Reply: Stephane CHAZELAS: "Re: Parsing a bash string?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|