[Haskell-cafe] Re: Parsing command lines
duncan.coutts at worc.ox.ac.uk
Mon May 25 11:57:01 EDT 2009
On Mon, 2009-05-25 at 17:45 +0200, Patai Gergely wrote:
> > There getArgs and getProgName in System module. If you want
> > parse this parameters there is System.Console.GetOpt.
> Those will only tell me how my program was called. I want to work with
> command lines as data within my program, which is a completely different
> > All the splitting, escaping and quotes interpretaion is done by
> > shell. All what get program when starts is list of
> > strings. Program name is actually arbitrary string. (At least
> > on unices, it may work a bit differently on windows).
> That's fine, but I'll see the commands yet to be passed to the shell as
> strings, and I'd like to know where to split them.
Trying to accurately emulate how the shell expands a command line string
into program argument strings is not easy. I don't know of any existing
Haskell library to do this but POSIX specifies a C function wordexp()
which does shell command line expansion. This might be more than you
want however as it also expands *.hs wildcards, arithmetic, quote
removal, ~user paths, $env vars and (optionally) $(command)
More information about the Haskell-Cafe