Disable rvm when using set -xv in shell script

When we use set -xv to debug a shell script, for every single command we get the entire execution path of utilities like rvm. It repeats for every single command in our script :slight_smile:

What is a good way to avoid sourceing RVM?

cd ${code_path}
+ cd ./lambda-functions/spec-validator
+ __zsh_like_cd cd ./lambda-functions/spec-validator
+ typeset __zsh_like_cd_hook
+ builtin cd ./lambda-functions/spec-validator
+ for __zsh_like_cd_hook in chpwd "${chpwd_functions[@]}"
+ typeset -f chpwd
+ for __zsh_like_cd_hook in chpwd "${chpwd_functions[@]}"
+ typeset -f __rvm_cd_functions_set
+ __rvm_cd_functions_set
+ __rvm_do_with_env_before
+ [[ -n '' ]]
+ [[ -n /opt/circleci/.rvm ]]
+ source /opt/circleci/.rvm/scripts/initialize
#!/usr/bin/env bash

If you need RVM, but donโ€™t want to see the output of each RVM command when using set -xv, you can redirect the output of the RVM commands to /dev/null:

rvm use ruby-2.7.2 >/dev/null 2>&1

This will prevent the output of the rvm use command from being displayed when you run your script with set -xv.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.