Issue
I am writing a bash
shell script that I can run on my local computer to update and redeploy a simple app hosted on an AWS E2 instance. I am having trouble with one line in particular: I cannot seem to activate a conda
environment within the ssh
command.
ssh -i $private_key_file $public_dns "conda activate ENVIRONMENT_NAME"
Returns:
bash: line 1: conda: command not found
However, if I ssh in with ssh -i $private_key_file $public_dns
and then run conda activate ENVIRONMENT_NAME
separatly this works fine.
What is happening? All other commands in my shell script are working fine with the ssh -i $private_key_file $public_dns "COMMAND"
syntax.
My instance is running Ubuntu 22.04 if relevant.
Solution
After some more searching, I found my .bashrc
file contained the following lines:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
I solved this problem by simply moving my conda
block above this line. I found this from the "community wiki"-owned response to this question.
What I tried:
- Sourcing my
.bashrc
file prior to runningconda activate ENVIRONMENT_NAME
. This did not solve the issue, apparently because it was still leaving the script on my non-interactive session. - Sourcing
.bashrc
in a.bash_profile
file, which is recommended as another top answer in the thread linked above. While this does work in sourcing.bashrc
, it still exists at the non-interactive condition.
Answered By - stat_is_quo Answer Checked By - Mary Flores (WPSolving Volunteer)