package tezt

  1. Overview
  2. Docs

Shell command representation.

This module is used for the subset of the shell language that is needed to operate remote runners through SSH. It makes sure that shell command are properly quoted.

type command = {
  1. local_env : (string * string) list;
  2. name : string;
  3. arguments : string list;
}

Commands.

Commands execute a program (whose executable name is name), with some arguments, possibly with some specific environment variables local_env to add to the current environment.

type t =
  1. | Cmd of command
    (*

    run a command

    *)
  2. | Seq of t * t
    (*

    run something, then something else (;)

    *)
  3. | Echo_pid
    (*

    echo the current process PID (echo $$)

    *)
  4. | Redirect_stdout of t * string
    (*

    redirect stdout to a file (>)

    *)
  5. | Redirect_stderr of t * string
    (*

    redirect stderr to a file (2>)

    *)
  6. | Or_echo_false of t
    (*

    run something, if it fails, print "false" (|| echo false)

    *)

Shell programs.

val to_string : ?context:[ `operator | `top ] -> t -> string

Convert a shell program into a string.

The result is quoted using shell syntax.

context specifies whether parentheses are needed:

  • `top means no parentheses are needed (default);
  • `operator means parentheses may be needed because this command is inside of an operator such as ; or ||.
val cmd : (string * string) list -> string -> string list -> t

Make a command to execute a program.

Usage: cmd local_env name arguments

Same as: Cmd { local_env; name; arguments }

val seq : t -> t -> t

Make a sequence.

Usage: seq command_1 command_2

Same as: Seq (command_1, command_2)

val redirect_stdout : t -> string -> t

Make an stdout redirection.

Usage: redirect_stdout command path

Same as: Redirect_stdout (command, path)

val redirect_stderr : t -> string -> t

Make an stderr redirection.

Usage: redirect_stderr command path

Same as: Redirect_stderr (command, path)

val or_echo_false : t -> t

Make a shell program that prints "false" if another program fails.

Usage: or_echo_false command

Same as: Or_echo_false command

OCaml

Innovation. Community. Security.