Is there any way, when running opam switch
, to turn off the blurb about needing opam env
next? I want to use opam switch
in a script, and it is indeed followed by sourcing the output of opam env
. But the blurb is distracting, I want the script to run silently when successful. And OTOH I don’t want to send stderr to /dev/null
lest I miss a real error message.
You can skip the opam switch
invocation and do eval $(opam env --switch=the_name --set-switch)
instead. It is equivalent to opam switch the_name && eval $(opam env)
. I am not 100% sure if the --set-switch
part is needed, but I believe so.
While I share your distaste at superfluous messages from commands I’d like to use in scripts, maybe this would help?
$ opam switch 4.10.1 | 2>&1 grep -v 'update the current'
$ opam switch 4.10.1
# Run eval $(opam env) to update the current shell environment
$ opam switch 4.10.1 | 2>&1 grep -v 'update the current'
$
Hi, I was going to do just this … but I just recently had to do it for another program [ 1] and I was a bit fed up @Khady suggestion looks perfect alhough I have not tested it yet.
[1] feed2exec
In a script you generally don’t want to run opam switch
, because it changes a global state, affecting later runs of opam
in other windows, for example.
In my experience, eval $(opam env --switch=...)
works fine, and has no side-effects beyond the current script.