package jenga

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
val escape : string -> string

Shell.escape arg quotes a string (if necessary) to avoid interpretation of characters which are special to the shell.

Shell.escape is used internally by jenga when displaying the "+" output lines, which show what commands are run; seen by the user when running jenga -verbose or if the command results in a non-zero exit code. It is exposed in the API since it is useful when constructing actions such as: Action.progress ~dir ~prog:"bash" ~args, which should ensure args are suitably quoted.

Examples: (1) escape "hello" -> "hello" (2) escape "foo bar" -> "'foo bar'" (3) escape "foo'bar" -> "'foo'\\''bar'"

Note the arg and result strings in the above examples are expressed using ocaml string literal syntax; in particular, there is only single backslash in the result of example 3.

Example (1): No quoting is necessary. Example (2): simple single quoting is used, since arg contains a space, which is special to the shell. Example (3): the result is single quoted; the embedded single quote is handled by: un-quoting, quoting using a bashslash, then re-quoting.

OCaml

Innovation. Community. Security.