ansible/dhall/Prelude/Text/shell-escape.dhall

17 lines
479 B
Text
Raw Normal View History

2024-11-26 05:55:44 +00:00
{-|
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