0

One of the steps to install pyenv requires typing the following into a terminal:

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

While I understand what echo -e and >> ./bash_profile do, I do not really understand what is going on inside the quotations marks.

After running the command above, my bash_profile now has the following:

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

Question: Could you explain what this code does? Is my interpretation of what is happening (see below) correct?

Interpretation:

  • command -v takes the name of a command and outputs its description, if the command given does not exist nothing is outputted; thus command -v pyenv will output the description pyenv if it is available (which will be if you installed pyenv), otherwise it will not show anything
  • the 1>/dev/null takes the output of the command -v pyenv and throws it away
  • What is the purpose for 2>&1?
  • Why do we need the eval inside the if block? Can't we just run pyenv init - directly?

Thanks for helping!

Guilherme Salomé
  • 1,899
  • 4
  • 19
  • 39

0 Answers0