Module Runner.Shell

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 = {
local_env : (string * string) list;
name : string;
arguments : string list;


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 =
| Cmd of command(*

run a command

| Seq of t * t(*

run something, then something else (;)

| Echo_pid(*

echo the current process PID (echo $$)

| Redirect_stdout of t * string(*

redirect stdout to a file (>)

| Redirect_stderr of t * string(*

redirect stderr to a file (2>)

| 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