0

How come the first one doesn't work and is not able to find conda on the PATH and the second works?

$ su - $NB_USER -c "echo $PATH && conda --version"
/opt/conda/condabin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
-sh: 1: conda: not found
$ sudo -u $NB_USER -- echo $PATH && conda --version
/opt/conda/condabin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
conda 4.9.2
2
  • 2
    In both commands, the $PATH value is from the interactive shell invoking su and sudo, not from the shell actually trying to invoke conda. This is due to the quoting with double quotes (1st command) and non-quoting (2nd command) of the command. In the second command, you don't even execute conda with sudo (the sudo command ends at &&). You may want to try sudo -u "$NB_USER" sh -c 'echo $PATH && conda --version' or something similar (I don't have sudo on my machine so can't test properly). – Kusalananda Feb 3 at 22:30
  • 1
    This is the correct answer, you should make it into an answer. – jsbillings Feb 4 at 0:37
1

I am making @Kusalananda's comment into a community answer, so that is question won't remain unanswered.

In both commands, the $PATH value is from the interactive shell invoking su and sudo, not from the shell actually trying to invoke conda. This is due to the quoting with double quotes (1st command) and non-quoting (2nd command) of the command. In the second command, you don't even execute conda with sudo (the sudo command ends at &&). You may want to try sudo -u "$NB_USER" sh -c 'echo $PATH && conda --version' or something similar (I don't have sudo on my machine so can't test properly).

1
  • Thanks! I don't use sudo or Linux, so I didn't have any way of testing. – Kusalananda Feb 15 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.