0

I want a command that I can add to my ~/.bashrc which does the following in this order:

  • cd to a directory
  • activate a conda environment
  • open a jupyter notebook.

The command that I have currently looks like this:

alias foo='
cd ~/Documents/bar
conda activate foobar
jupyter notebook
'

But execution stops after the conda activate foobar command.

Is there a way that I can ensure that all 3 commands are performed, and that it does not stop when I go into a new environment?

  • Use a function, not an alias, for compound commands. Beyond that, check that `conda activate` modifies the state of the shell you already were running; if it starts a new shell instead, *of course* that new shell won't continue executing the same function or alias. – Charles Duffy Feb 08 '20 at 00:52
  • One way you can test that is to look at whether running `conda activate` changes `$BASHPID`. Alternately, you can look at `type conda`. If `conda` itself is a function, it could be capable of modifying the state of your running shell. If it's an external script (and is executed as such rather than sourced), starting a new shell is the only way it could possibly be implemented. – Charles Duffy Feb 08 '20 at 00:53
  • Alternately, you might consider the approach taken by the already-answered question https://stackoverflow.com/questions/34534513/calling-conda-source-activate-from-bash-script – Charles Duffy Feb 08 '20 at 03:03
  • Or add `;` between commands, carriage returns will not work in an alias. – Nic3500 Feb 08 '20 at 04:15

0 Answers0