First of all, the modern syntax is eval $(opam env)
, which uses $(...)
instead of the deprecated backticks and a shorterned command opam env
, which is available since opam 2.1.
This invocation is used to initialize the environment variables of your shell1. These variables are necessary for the toolchain to work correctly, e.g., CAML_LD_LIBRARY_PATH
tells the compiler where to search for the OCaml libraries.
Here, eval
is a built-in command of your shell that evaluates its argument. And backticks (or, the preferred, $(...)
syntax) perform command substitution, i.e., they evaluate what they delimit and substitute the contents with the output of the evaluated expression.
The opam env
command, returns a small shell program,
$ opam env
OPAM_SWITCH_PREFIX='/home/ivg/.opam/dev'; export OPAM_SWITCH_PREFIX;
CAML_LD_LIBRARY_PATH='/home/ivg/.opam/dev/lib/stublibs:/home/ivg/.opam/dev/lib/ocaml/stublibs:/home/ivg/.opam/dev/lib/ocaml'; export CAML_LD_LIBRARY_PATH;
OCAML_TOPLEVEL_PATH='/home/ivg/.opam/dev/lib/toplevel'; export OCAML_TOPLEVEL_PATH;
PKG_CONFIG_PATH='/home/ivg/.opam/dev/lib/pkgconfig:'; export PKG_CONFIG_PATH;
MANPATH=':/home/ivg/.opam/dev/man'; export MANPATH;
PATH='/home/ivg/.opam/dev/bin:/home/ivg/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'; export PATH;
So when you do eval $(opam env)
, eval
executes the program returned by opam env
and assigns the proper values to these variables.
1)) This is a rather common approach for setting up a toolchain, cf. virtualenv
in Python.
eval $(opam env)
? #72522912 – BoatyardThis is most usefully used as eval $(opam env) to have further shell commands be evaluated in the proper opam context.
in opam.ocaml.org/doc/man/opam-env.html what does it mean? – Boatyardeval
and$(...)
? – Boatyard