I am trying to print colored texts in terminal using echo -e ‘\x1b[31mhello world\x1b[0m’. Everything is well in the terminal when I type this myself, but the code below outputs “-e \x1b[31mhello world\x1b[0m” itself. What’s the problem? How can I fix it?
let _ =
ignore (Sys.command ("echo -e '\\x1b[31mhello world\\x1b[0m'"))
Heh indeed. It is for this very reason that the helper scripts I wrote for camlp5 and pa_ppx that need to do all sorts of shell-quoting … are written in Perl, and not in OCaml. I simply didn’t want to figure out all the quoting b.s., and it wasn’t relevant to the goals of the actual code being implemented.
If I had to do this, I’d sooner learn how to use terminfo (or termcap, or ncurses) from OCaml, than try to use the shell.