Fix an hard-to-track bug when PATH contains garbage

This is related to https://github.com/ocaml/opam-repository/issues/1306

Note: untested.

Feel free to adapt and improve.