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; thuscommand -v pyenv
will output the descriptionpyenv
if it is available (which will be if you installedpyenv
), otherwise it will not show anything- the
1>/dev/null
takes the output of thecommand -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 runpyenv init -
directly?
Thanks for helping!