ansible/dhall/Prelude/Text/shell-escape.dhall
2024-11-26 00:55:56 -05:00

16 lines
479 B
Text

{-|
Escape a Text value such that it can be used safely in shells.
The escaping is done by replacing all `'` with `'"'"'` and wraps that string in
single quotes.
This works for all POSIX-compliant shells and some other shells like csh.
-}
let shell-escape
: Text -> Text
= \(xs : Text) -> "'${Text/replace "'" "'\"'\"'" xs}'"
let example0 = assert : shell-escape "foo" === "'foo'"
let example1 = assert : shell-escape "foo'bar" === "'foo'\"'\"'bar'"
in shell-escape