shellwords: Parse strings into words, like a shell would

[ library, mit, text ] [ Propose Tags ]


[Skip to Readme]
Versions [faq],,,,
Change log
Dependencies base (>=4.7 && <5), megaparsec (>=7.0.0), text [details]
License MIT
Copyright 2018 Patrick Brisbin
Author Patrick Brisbin
Category Text
Home page
Bug tracker
Source repo head: git clone
Uploaded by PatrickBrisbin at Thu Feb 7 19:23:17 UTC 2019
Distributions NixOS:
Downloads 579 total (42 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-02-07 [all 1 reports]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees

Readme for shellwords-

[back to package description]


Parse a string into words, like a shell would.


If you need to execute commands given to you as user-input, you should know not to give that text as-is to a shell:

callProcess "sh" ["-c", "some --user --input"]

Such code is a severe security vulnerability. Furthermore, any attempts to sanitize the string are unlikely to be 100% affective and should be avoided. The only safe way to do this is to not use a shell intermediary, and always exec a process directly:

callProcess "some" ["--user", "--input"]

The new problem (and not a security-related one) is how to correctly parse a string like "some --user --input" into the command and its arguments. The rules are complex enough that you probably want to get a library to do it.

So here we are.


Right (cmd:args) <- parse "some -complex --command=\"Line And\" 'More'"

callProcess cmd args
-- Is equivalent to:
-- > callProcess "some" ["-complex", "--command=Line And", "More"]


This package is inspired by and named after